/* Milk light potentiometer code * ----------------------------- * * By David Hayward * * www.instructables.com/member/Nachimir * * Turns a bank of LED lights on and off in sequence depending on the reading from a potentiometer. * * Based partly on Analog Read to LED by DojoDave */ int potPin = 2; // select the input pin for the potentiometer (Analog pin AD2) int led1 = 4; int led2 = 5; int led3 = 6; int led4 = 7; int led5 = 8; int led6 = 9; int led7 = 10; int led8 = 11; int led9 = 12; int led10 = 13; int led11 = 14; int led12 = 15; int val = 0; // variable to store the value coming from the sensor void setup() { pinMode(led1, OUTPUT); // declare the ledPin as an OUTPUT pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(led6, OUTPUT); pinMode(led7, OUTPUT); pinMode(led8, OUTPUT); pinMode(led9, OUTPUT); pinMode(led10, OUTPUT); pinMode(led11, OUTPUT); pinMode(led12, OUTPUT); } void loop() { if (digitalRead(6) == HIGH && digitalRead(5) == LOW) { digitalWrite(led3, LOW); // the mini sets this pin high upon startup for some reason } val = analogRead(potPin); // read the value from the sensor if (val <= 30) { digitalWrite(led1, LOW); // set last pin to LOW when turning potentiometer down. } if (val >= 35){ digitalWrite(led1, HIGH); // set 1st HIGH when turning up, keep HIGH when turning down. digitalWrite(led2, LOW); // set 2nd low when turning down. } if (val >= 48){ digitalWrite(led2, HIGH); digitalWrite(led3, LOW); } if (val >= 65){ digitalWrite(led3, HIGH); digitalWrite(led4, LOW); } if (val >= 90){ digitalWrite(led4, HIGH); digitalWrite(led5, LOW); } if (val >= 144){ digitalWrite(led5, HIGH); digitalWrite(led6, LOW); } if (val >= 180){ // this is approx half the travel of the log pot I used digitalWrite(led6, HIGH); digitalWrite(led7, LOW); } if (val >= 255){ digitalWrite(led7, HIGH); digitalWrite(led8, LOW); } if (val >= 340){ digitalWrite(led8, HIGH); digitalWrite(led9, LOW); } if (val >= 480){ digitalWrite(led9, HIGH); digitalWrite(led10, LOW); } if (val >= 660){ digitalWrite(led10, HIGH); digitalWrite(led11, LOW); } if (val >= 870){ digitalWrite(led11, HIGH); digitalWrite(led12, LOW); } if (val >= 1001){ digitalWrite(led12, HIGH); } }