Hello
After not using my netduino for almost a year I want to get back into it now that I am home from university for the summer. I've been trying to brush up on what I learned, so bear with me if I mess something simple up.
So about a year ago I was pretty much just playing with the onboard led, learning about pwm and making it fade in and out as well as using the button to turn the led on and off as seen in one of the example videos. However I am stuck at how to 'pause' the flashing or pulsing led with the button. Last year I was able to do it but if I pressed the button at the wrong time it would 'miss' the input in the while loop.
To summarize what I want to do is to be able to press the button to stop the blinking and then press it again to start the blinking again.
ex. controlling this code:
public static void Main() { // write your code here OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); while (true) { led.Write(true); // turn on the LED Thread.Sleep(250); // sleep for 250ms led.Write(false); // turn off the LED Thread.Sleep(250); // sleep for 250ms } }
with the button. I know I can put the button.Read() command in the while loop condition and then put all of that in another while loop, but this starts to fall apart when I go to more complex fading or other patterns that may take a second or too to get through so if I press the button when its not looking for it then the blinking continues on.
I believe the answer would have something to do with threading or event handlers but I can't seem to wrap my head around them, or been able to find an example for the netduino that does a similar thing. If anyone has a good tutorial on how to build event handlers and making events (is this the right terminology?) as well as using threads it would be greatly appreciated.
I assume a similar method with threading would be used if I wanted to maybe blink an led while doing other things which I would also like to eventually learn how to do.
Thanks for your help!