Last active
October 6, 2015 15:46
-
-
Save jessherzog/d4e91010b22dd1e3484a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// six pins instead of three. | |
int ledPin1 = 8; | |
int ledPin2 = 9; | |
int ledPin3 = 10; | |
int ledPin4 = 11; | |
int ledPin5 = 12; | |
int ledPin6 = 13; | |
int ledPins[6] = (8, 9, 10, 11, 12, 13); | |
// and here | |
void setup() { | |
pinMode(ledPin1, OUTPUT); | |
pinMode(ledPin2, OUTPUT); | |
pinMode(ledPin3, OUTPUT); | |
pinMode(ledPin4, OUTPUT); | |
pinMode(ledPin5, OUTPUT); | |
pinMode(ledPin6, OUTPUT); | |
// add three more here | |
} | |
void loop() { | |
// read the input on analog pin 0: | |
int sensorValue = analogRead(A0); | |
// The analog pin reads from 0 to 1023. | |
// This commands maps those numbers from 4 to 0 | |
// So 0 becomes 4 and 1023 becomes 0 | |
int mappedSensorValue = map( sensorValue, 0, 1023, 7, 0); | |
// map (input from pot, range of numbers maps to other range of numbers) | |
// reversing the range changes the order of what happens | |
// when adding three more, make second range 7 - 0 | |
// Here we test the mappedsensorvalue. If it is greater then 1 we turn | |
// on the LED on Pin 2 and then see if it is greater then 2. | |
switch (mappedSensorValue) { | |
case >1: | |
digitalWrite ( ledPin6, HIGH); | |
break; | |
case >2: | |
digitalWrite ( ledPin5, HIGH); | |
break; | |
case >3: | |
digitalWrite ( ledPin4, HIGH); | |
break; | |
case >4: | |
digitalWrite ( ledPin3, HIGH); | |
break; | |
case >5: | |
digitalWrite ( ledPin2, HIGH); | |
break; | |
case >6: | |
digitalWrite ( ledPin1, HIGH); | |
break; | |
default: | |
digitalWrite (ledPins[6], LOW); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment