LOW and HIGH Values Reversed For Code on Particle Photon


#1

I am new to Zerynth and I didn’t see anything about this in the community forum so maybe it’s me but I was writing code just to blink the Red, Green and Blue leds (LED0, LED1 and LED2) by using the digitalWrite(LED0, HIGH) for ON and digitalWrite(LED0, LOW) for OFF on each LED and I was not getting the correct results. I figured out that HIGH was OFF and LOW was ON. Is there a way for me to correct the HIGH and LOW values?

Thanks

So below is the way I had to write the code to get the correct blinking of LEDs:

pinMode(LED0,OUTPUT)
pinMode(LED1,OUTPUT)
pinMode(LED2,OUTPUT)

digitalWrite(LED0, HIGH) # turn the LED OFF by setting the voltage HIGH
digitalWrite(LED1, HIGH) # turn the LED OFF by setting the voltage HIGH
digitalWrite(LED2, HIGH) # turn the LED OFF by setting the voltage HIGH

loop forever

while True:
digitalWrite(LED0, LOW) # turn the LED ON by setting the voltage HIGH
sleep(1000) # wait for a second
digitalWrite(LED0, HIGH) # turn the LED OFF by setting the voltage LOW
sleep(500) # wait for a second
digitalWrite(LED1, LOW) # turn the LED ON by setting the voltage HIGH
sleep(1000) # wait for a second
digitalWrite(LED1, HIGH) # turn the LED OFF by setting the voltage LOW
sleep(500) # wait for a second
digitalWrite(LED2, LOW) # turn the LED ON by setting the voltage HIGH
sleep(1000) # wait for a second
digitalWrite(LED2, HIGH) # turn the LED OFF by setting the voltage LOW
sleep(500) # wait for a second


#2

Hi @pzacjr,

it sometimes happens that LEDs are turned on with a digital pin on its 0 value and turned off on its 1 value.
This seems to be the Particle Photon case.

So, while digitalWrite(pin, HIGH) always means set the value of pin to 1, it might mean turn the LED on or off depending on how the LED has been mounted.


#3

Hello LorenzoR,

I did some more tinkering and it is only the RGB LED (LED0, LED1 and LED2 or D12, D13 and D14) that has this issue, other LEDs that you wire on a board and even LED3 (D7) works properly.
In the Photon environment they use RGB.control for the RGB LED.
I am glad it is only the RGB led that has the issue.

Thanks for your help.
Peter