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:

The mbed-enabled LPC4088 QuickStart Board from Embedded Artists is a easy to use ARM Cortex-M4 rapid prototyping board in a standard through hole DIP package (44-pin), targeted at high-performance as …

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 Dan D. 03 Feb 2014

DigitalOut is just that: it sets a pin high or low. If you inverse the behavior for LEDs you get really weird situations.

posted by Erik - 03 Feb 2014

You 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 Wim Huiskamp 03 Feb 2014