Closed gfeun closed 4 years ago
Hi Glenn!
Great to hear from you again :-)
At the moment, the GPIO module only includes the pinState()
function, which queries the current state of the pins.
It does make a lot of sense to add another method that will let you set the state of a pin. One of the main challenges is correctly dealing with pull-ups. For instance, let's say that your virtual button connects the pin with GND. When the button is not pressed, the pin is floating. What value should the user code get when reading from the pin if the pull-up is not used?
We now have a new setPin()
method for this purpose. Note that this is a breaking change since now setting the PIN
memory location directly (as you did above) will be overridden by the AVRIOPort
class. The new method should be a part of the upcoming 0.9.0 release
Released as part of 0.9.0
Hello again !
So I have made some progress on my virtual training board using avr8js. I have 8 leds + 8 pushbutton. Using demo project it was quite easy to set up.
I am now wondering if there is a "nice" way to hook up the pushbuttons to a specific µController GPIO port.
What I am doing now is register some event listener on the push-button events. On event, I access cpu register directly and modify the internal cpu data field of the corresponding register
This is working, with the following code i have a "blink led according to button pressed":
But i find modifying the internal cpu data directly looks like a hack and i may have missed the "proper" way to do it. Do you have any recommendation or good practice on how to do it ?
Thank you !