LEDx.toggle()? #5584
Replies: 1 comment
-
Posted at 2017-01-20 by @allObjects What about having this global function uploaded? It will toggle any pin:
To be on the safe side - NOT make an input pin an output pin - use this code:
...and prototype-based-object-oriented, upload this expression, which will give you the .toggle():
Posted at 2017-01-20 by @gfwilliams
Yes, pretty much right since the start :) I've resisted putting toggle in so far because it's only use is really for LEDs. People think it's just What @allObjects is suggesting ( Posted at 2017-01-20 by @gfwilliams I just added a It's worth noting that it it doesn't work on the ESP8266 port, because on that the internal Posted at 2017-01-20 by Ollie Excellent, thank you! I could see that uploading a bit of code would be easy enough, but to have this available out the box is much better! Posted at 2017-01-20 by Wilberforce @gfwilliams. For the esp the pin state is saved in array - so that could be used for the toggle. https://github.com/espruino/Espruino/blob/master/targets/esp8266/jshardware.c#L420 This might just work out of box:
Once this is up on github, we can take a look and also add it to the esp32 port - or a least document as a todo. Posted at 2017-01-23 by @gfwilliams You might want to add:
I think that'll do it - just depends if that register can be read or not. Basically It makes stuff like Posted at 2017-01-24 by @MaBecker Did some tests
can be used for this, created PR #1034 Posted at 2017-01-24 by @gfwilliams merged. So 1v92 should have this in Posted at 2017-01-26 by Wilberforce
If the hardware is getting read - is there any point in using the And I don't follow why the OR is used? Thanks Posted at 2017-01-26 by @MaBecker Hi @wilberforce, JshPinGetState() now returns pinState "or" JSHPINSTATE_PIN_IS_ON if pin is high. jswrap_pin_toggle() can use JshPinState() to set Posted at 2017-01-26 by Wilberforce Yes - I don't understand why the OR is used, if the hardware is getting read - then that would be sufficient I would have thought? Posted at 2017-01-27 by @gfwilliams edit: didn't see the previous posts. jshPinGetState does a lot more than just return whether the pin is on or off, it does 'pullup'/'input'/'output'/etc - it's what is used for |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-01-19 by Ollie
There's a bit of code required to toggle an LED. The LEDx.set/reset functions help (which I'd not used before getting a Puck - were they available before?), but it struck me that a
LEDx.toggle()
abstraction would be really useful, in general, and especially when sending commands over BLE/between Pucks given the buffer limit.Is this feasible?
Beta Was this translation helpful? Give feedback.
All reactions