Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 5 months ago.
LEDs reverse logic?
Hello,
When doing basic LED I/O write using examples like Hello World, i notice that the logic is reversed. led1=1 turns it off and led1 = 0 turns it on. Is this expected behavior?
Thanks
Question relating to:
![](/media/cache/platforms/ea-lpc4088.png.50x50_q85.png)
1 Answer
10 years, 5 months ago.
You would have to lookup the schematic on the Embedded Artists website, but it is likely that they use the regular circuitry for an LED: connect the cathode to the portpin and connect the anode to Vcc through a series resistor. That means the LED is on when the pin is low. The mbed modules are different from normal convention in that they connect the LED anode to the port pin which makes the LED turn on when you write a high level.
Thanks. I understand the circuit, but i would have guessed mbed would have standardized the behavior in their libraries. It'd be simple to do and stuff like this makes moving platforms just a little more hassle.
posted by 03 Feb 2014DigitalOut is just that: it sets a pin high or low. If you inverse the behavior for LEDs you get really weird situations.
posted by 03 Feb 2014You could fix it in software for the onboard LEDs when they are identified by the special names LED1 etc, but that would not solve the problem for any other pins that you use to connect LEDs. It gets even weirder when the LED pin is not configured as DigitalOut but as PWM. In that case a different connection circuit results in an LED that is off when the duty cycle is set at 100%. Best option would have been to use same circuitry, but that train has left the station..LPC800 max, Dipcortex etc have the same issues.
posted by 03 Feb 2014