Skip to content

Instantly share code, notes, and snippets.

@gatana
Created October 5, 2015 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatana/1cd13f6c4da674a6cd92 to your computer and use it in GitHub Desktop.
Save gatana/1cd13f6c4da674a6cd92 to your computer and use it in GitHub Desktop.
int ledPin1 = 11;
int ledPin2 = 12;
int ledPin3 = 13;
int ledPin4 = 10;
int ledPin5 = 9;
int ledPin6 = 8;
void setup() {
pinMode(ledPin1,OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(ledPin3,OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
}
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
Serial.println(sensorValue);
int mappedSensorValue = map( sensorValue, 0, 1023, 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.
if (mappedSensorValue > 1) {
digitalWrite (ledPin1, HIGH);
if (mappedSensorValue > 2) {
digitalWrite (ledPin2, HIGH);
if (mappedSensorValue > 3) {
digitalWrite (ledPin3, HIGH);
if (mappedSensorValue > 4) {
digitalWrite (ledPin4, HIGH);
if (mappedSensorValue > 5) {
digitalWrite (ledPin5, HIGH);
if (mappedSensorValue > 6) {
digitalWrite (ledPin6, HIGH);
}
else{//If it is not greater we start turning LEDs off.
digitalWrite (ledPin6, LOW);
}
}
else{
digitalWrite (ledPin5, LOW);
}
}
else{
digitalWrite (ledPin4, LOW);
}
}
else{
digitalWrite (ledPin3, LOW);
}
}
else{
digitalWrite (ledPin2, LOW);
}
}
else{
digitalWrite (ledPin1, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment