hello all, as i,m new to arduino, i,v esp8266 ch340 module and i,v searched several rgb projects on google and i,v also made some sample projects myself on learning base, problem is all tutorial on net using codes for full brightened/on leds @ 255 and dim/off @ 0, but on my side total opposite mine codes works with dim or off @ 255 and full bright or on @ 0. even switches works total opposite HIGH is LOW and LOW is HIGH. is there any solution ? thanks in advance.
Wire them the other way.
Mathematics to the rescue.
If you have a number x 0 to 255 then 255 - x will neatly go from 255 to 0.
unsigned char y = 255 - x; / goes the opposite way
If your switches are "upside down", you can fix that right when you digitalRead them:
unsigned char pressed = ! digitalRead(somePin);
The ! is the logical inversion operator, so HIGH becomes LOW and vice versa.
HTH
a7
do you mean LOW is when it is pressed and HIGH is not being pressed. the conventional approach is to connect the button between the pin and ground, configure the pin as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and for the button to pull the pin LOW.
and as suggested, the LEDs may be wired between 5V and the pin, so making the pin LOW turns the LED on
Idahowalker, alto777, gcjr, bundle of thanks all you guys. really appreciated your help and many thanks for good solutions.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.