Skip to content

Instantly share code, notes, and snippets.

@jessherzog
Last active October 6, 2015 15:46
Show Gist options
  • Save jessherzog/d4e91010b22dd1e3484a to your computer and use it in GitHub Desktop.
Save jessherzog/d4e91010b22dd1e3484a to your computer and use it in GitHub Desktop.
// 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