NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Simple micro controlled light switch
August 20, 2012 by bakerboy |
I want to have a light turn on and off by using in PD0 as an input, when the pin is high an led connected to PC4 should be on, when it is low the led should turn off. Below is my code i am trying to use to do this, it is a modified version of led_blink. This is my first project after completing the guide. I know its a code issue, just not sure where, any help would be amazing.
|
---|---|
August 21, 2012 by pcbolt |
Hi bakerboy - I think the problem might be on line 27...
This will not always evaluate to "true" when PD0 is low. The code block following the "if" expression will execute only if the value inside the parenthesis evaluates to something other than zero. If you step through the expression the way the MCU does it will compute this in order... (let's say all the pins of PORTD are low)
The easiest way to correct this problem is to replace line 27 with...
If you want an expression that tests for a single low pin you can use...
|
Please log in to post a reply.
Did you know that Pulse Width Modulation (PWM) can be used to control the speed of a motor digitally? Learn more...
|