Devices & Components
Resistor 220 ohm
5 mm LED: Red
Single Turn Potentiometer- 10k ohms
Project description
Code
Coding (written for an Arduino Uno)
arduino
1const int potPin = A0; 2int potVal = 0; 3int led = 0; 4 5void setup() { 6 Serial.begin(9600); 7 for(int x = 2; x < 8; x++){ 8 pinMode(x, OUTPUT); 9 } 10 pinMode(potPin, INPUT); 11} 12 13void loop() { 14 potVal = analogRead(potPin); 15 Serial.print(potVal); 16 led = map(potVal, 0, 1023, 0, 6); 17 Serial.print(" "); 18 Serial.println(led); 19 if(led == 0){ 20 for(int x = 2; x < 8; x++){ 21 digitalWrite(x, LOW); 22 } 23 } 24 if(led == 1){ 25 for(int x = 2; x < 8; x++){ 26 digitalWrite(x, LOW); 27 } 28 digitalWrite(2, HIGH); 29 } 30 if(led == 2){ 31 for(int x = 2; x < 8; x++){ 32 digitalWrite(x, LOW); 33 } 34 for(int x = 2; x < 4; X++){ 35 digitalWrite(x, HIGH); 36 } 37 } 38 if(led == 3){ 39 for(int x = 2; x < 8; x++){ 40 digitalWrite(x, LOW); 41 } 42 for(int x = 2; x < 5; X++){ 43 digitalWrite(x, HIGH); 44 } 45 } 46 if(led == 4){ 47 for(int x = 2; x < 8; x++){ 48 digitalWrite(x, LOW); 49 } 50 for(int x = 2; x < 6; X++){ 51 digitalWrite(x, HIGH); 52 } 53 } 54 if(led == 5){ 55 for(int x = 2; x < 8; x++){ 56 digitalWrite(x, LOW); 57 } 58 for(int x = 2; x < 7; X++){ 59 digitalWrite(x, HIGH); 60 } 61 } 62 if(led == 6){ 63 for(int x = 2; x < 8; x++){ 64 digitalWrite(x, LOW); 65 } 66 for(int x = 2; x < 8; x++){ 67 digitalWrite(x, HIGH); 68 } 69 } 70}
Downloadable files
Wiring on a breadboard
Wiring on a breadboard

Wiring on a breadboard
Wiring on a breadboard

Comments
Only logged in users can leave comments