writing modules using new feature class #1260
Replies: 3 comments
-
Posted at 2018-02-26 by Wilberforce Thanks for this. It might tidy modules up quite a bit. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-12-19 by @MaBecker Here is one more I named LED. It is a very simple class the can handle three led states: on / off / blink( duration in ms for off and on) Some led are switched on with Pin.write(1) and some with Pin.write(0) thats why the constructor needs two parameter, one for the pin and one for the value used to switch the led on.
Code to test class LED on a Pico
Hope it is useful ;-) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-12-19 by @gfwilliams Just to add to this, there's another 'hack' for things like this - since you can add to the built-in classes in Espruino, it is possible to just extend
The gotcha here is that there's no storage for fields (like the interval's ID) in the Pin itself, so you'd have to store them elsewhere, like maybe in a closure:
In reality it's maybe not as clean as @MaBecker's suggestion, but it's an interesting thing to be aware of :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-02-24 by @MaBecker
Like to share how to write a module containing a class
and use it.
Beta Was this translation helpful? Give feedback.
All reactions