Pages: [1]   Go Down
Author Topic: How can I create 4 cases out of one analog input??  (Read 512 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

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!!!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27353
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

basically:
Code:
void loop(){
potvalue=analogRead(A0);
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 ...
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34524
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And get the syntax right in the if statement.
Logged

Pages: [1]   Go Up
Jump to: