The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
Hi dustmouse,
You could also use a timer to launch an event every ## ms if you wanted. And then disable that timer when you want to stop the LED.
Personally, I would create a thread to blink the LED and have a class-wide "_ledBlinkDisabled" variable. Then you simply set that variable to true when you want the LED to stop blinking. We do this sometimes in applications with sync locks and two variables and it works consistently well.
Chris
Go to the full post
Is there a way to wire an AnalogInput to an event so that when the physical input changes, it raises an event? Like for an LED dimmer. I'm hoping for something similar to InterruptPort.OnInterrupted? I know that you can accomplish the desired behavior in a while(true) loop, but I don't want it to be trapped in a loop forever - unless I can stick it on a different thread...
If there isn't something out-of-the-box, can I create my own custom event that is wired to the AnalogInput hardware (without my brain melting)? So far, my experience with ICs is making the onboard LED turn on and off with the onboard button, so I'm still very wet behind the ears.
Is there a way to wire an AnalogInput to an event so that when the physical input changes, it raises an event?
If there isn't something out-of-the-box, can I create my own custom event that is wired to the AnalogInput hardware (without my brain melting)?
Currently you have to poll the analogue ports when you want to take a reading. You could write your own class which polled the ports on a regular basis and then generated an interrupt if the difference between the last reading and the current one was outside of a certain tolerance. Would be an interesting little software project.
Is there a way to wire an AnalogInput to an event so that when the physical input changes, it raises an event? Like for an LED dimmer. I'm hoping for something similar to InterruptPort.OnInterrupted? I know that you can accomplish the desired behavior in a while(true) loop, but I don't want it to be trapped in a loop forever - unless I can stick it on a different thread...
If there isn't something out-of-the-box, can I create my own custom event that is wired to the AnalogInput hardware (without my brain melting)? So far, my experience with ICs is making the onboard LED turn on and off with the onboard button, so I'm still very wet behind the ears.
Check out this thread it may be what you are looking for.
Currently you have to poll the analogue ports when you want to take a reading. You could write your own class which polled the ports on a regular basis and then generated an interrupt if the difference between the last reading and the current one was outside of a certain tolerance. Would be an interesting little software project.
Regards,
Mark
Thanks, Mark. I like your polling idea. I'd like to give that a shot.
I actually haven't picked up a potentiometer yet - just got a little ahead of myself in the Getting Started with Netduino book .
Thanks, Dave. I don't actually have a potentiometer yet, so I went off of that example to create an event that would let an LED blink until it received an interrupt request.
I made a Cycled event on the LED that was raised after each blink iteration, and I had a button subscribe to the event. The only issue was that you would have to make sure you were holding the button down until the next time the event was raised, which wasn't a problem on fast blinking, but wasn't very elegant on slow blinking.
When I get a pot, I'll revisit the example in your link.
I know in standard .NET programming, it is generally frowned upon to use Thread.Abort() to stop a thread because you don't know what state it will be in when it is aborted. But when working with basic components in the Micro Framework, is it as much of an issue?
I created a blinking LED that when set to 'on', blinks ad infinitum on a separate thread. When set to 'off' it aborts the thread, stopping the blinking. The hardware behavior is correct. And the button doesn't have to worry about interrupting the blinking itself, it just turns the LED on and off.
The only reason I'm using a separate thread and aborting is because the only way I've found to create blinking behavior in an LED is by turning it on/off in an infinite loop. I don't want to use a count down (no matter how big) to turn it off - but have it keep blinking until an input component like a button turns it off. Is there a better way of accomplishing this?
The only reason I'm using a separate thread and aborting is because the only way I've found to create blinking behavior in an LED is by turning it on/off in an infinite loop. I don't want to use a count down (no matter how big) to turn it off - but have it keep blinking until an input component like a button turns it off. Is there a better way of accomplishing this?
You could always use a Timer. The code in that post uses a GPIO pin for output but these is no reason that could not be the onboard LED.
Hi dustmouse,
You could also use a timer to launch an event every ## ms if you wanted. And then disable that timer when you want to stop the LED.
Personally, I would create a thread to blink the LED and have a class-wide "_ledBlinkDisabled" variable. Then you simply set that variable to true when you want the LED to stop blinking. We do this sometimes in applications with sync locks and two variables and it works consistently well.
Chris
Hi dustmouse,
You could also use a timer to launch an event every ## ms if you wanted. And then disable that timer when you want to stop the LED.
Personally, I would create a thread to blink the LED and have a class-wide "_ledBlinkDisabled" variable. Then you simply set that variable to true when you want the LED to stop blinking. We do this sometimes in applications with sync locks and two variables and it works consistently well.
Chris
Thanks, Chris. So if I understand what you're suggesting, I would still use a separate thread for the blinking, but the LED behavior can be changed by setting the _ledBlinkDisabled value.
If _ledBlinkDisabled is true, then does it just receive a constant high voltage, displaying solid light?
Would you still need to abort the thread to kill the blinking?
If _ledBlinkDisabled is true, then does it just receive a constant high voltage, displaying solid light?
Would you still need to abort the thread to kill the blinking?
Basically, every time your background thread changed the state of the LED...it would watch the blinking disabled flag.
If the flag was set to true, you could either [a] simply set the LED to off for that blink cycle or return from the function and exit that thread. It depends on how you prefer to restart blinking (i.e. by simply setting the flag to false or by starting up the thread again).
Chris
Basically, every time your background thread changed the state of the LED...it would watch the blinking disabled flag.
If the flag was set to true, you could either [a] simply set the LED to off for that blink cycle or return from the function and exit that thread. It depends on how you prefer to restart blinking (i.e. by simply setting the flag to false or by starting up the thread again).
Chris
Okay, that is way more cleaner than aborting the thread. Thanks!