Go Down

Topic: How can I create 4 cases out of one analog input?? (Read 666 times) previous topic - next topic



It's maybe a simple question but I can't figure it out: I have four transistors driving 4 different banks of leds. I have one potentiometer hooked up to the analog input A0. I want to switch through the colours as I sweep the pot. So e.g. 0 - 255 = Transistor 1 high, others low, 256 - 511 Transistor 2 high, others low and so on.

Thank you so much for your help!!!


Code: [Select]

void loop(){
if (potvalue>=0 and potvalue<=255){digitalwrite (LED1, High (assuming High - on);}
else {digitalwrite (LED1, Low (assuming High - on);}

repeat for 255-511,512-767, 768-1023 or as you see fit

flesh out variable names & stuff ...
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Ok, super! Great! A thousand thanks for that!!!


And get the syntax right in the if statement.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131