/*
--------------------------------------------

Maker Magazine - Force Sensor Demo

This simple program visually shows the amount of force placed on the sensor
There are much more efficient ways to program, this way was chosen because
it is very easy to understand.

By Marc de Vinck © Creative Commons....whatever.

 --------------------------------------------
*/

// Here are the constants that we define prior to the program running

int forcePin = 2;    // select the input pin for the force sensor
int val = 0;         // variable to store the value coming in from the sensor

int led1=9;          // defines "led1" as the number 9
int led2=10;         // defines "led2" as the number 10
int led3=11;         // defines "led3" as the number 11
int led4=12;         // defines "led4" as the number 12
int led5=13;         // defines "led5" as the number 13

// End of constant definitions

void setup()                    //run one time when the Arduino first powers up
{
  Serial.begin(9600);           //starts serial communication, only used for debgugging

  pinMode(led1, OUTPUT);        // remeber led1 = pin 9,  this statement sets pin 9 to output only
  pinMode(led2, OUTPUT);        // remeber led2 = pin 10, this statement sets pin 10 to output only
  pinMode(led3, OUTPUT);        // remeber led3 = pin 11, this statement sets pin 11 to output only
  pinMode(led4, OUTPUT);        // remeber led4 = pin 12, this statement sets pin 12 to output only
  pinMode(led5, OUTPUT);        // remeber led5 = pin 13, this statement sets pin 13 to output only
}

void loop()                        //This next bit of code runs continuously
{

  val = analogRead(forcePin);    // read the value from the sensor

  Serial.println(val,DEC);        // print the value "val" of the sensor (used for debugging)

  if (val>250){                 //if the value is maxed out or greater than 250

    // aternative code for the following -----for (i=1; i<6; i=i++); digitalwrite(led[i],HIGH)

    digitalWrite(led5,HIGH);   // turns on all 5 LEDs
    digitalWrite(led4,HIGH);
    digitalWrite(led3,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
 delay(100);                    //slight delay to minimize flickering
  }
  else{
    digitalWrite(led5,LOW);    //turn off all 5 LEDs
    digitalWrite(led4,LOW);
    digitalWrite(led3,LOW);
    digitalWrite(led2,LOW);
    digitalWrite(led1,LOW);
  }

  if (val>=175 && val<=250){    //if value is between 100 and 175
    digitalWrite(led4,HIGH);    //turns on 4 LEDs
    digitalWrite(led3,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
  delay(100);                   //slight delay to minimize flickering
  }
  else{
    digitalWrite(led4,LOW);    //turns off 4 LEDs
    digitalWrite(led3,LOW);
    digitalWrite(led2,LOW);
    digitalWrite(led1,LOW);
  }

  if (val>=100 && val<=175){    //if value is between 100 and 175
    digitalWrite(led3,HIGH);    //turns on 3 LEDs
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
 delay(100);                   //slight delay to minimize flickering
}
  else{
    digitalWrite(led3,LOW);    // you get the picture....
    digitalWrite(led2,LOW);
    digitalWrite(led1,LOW);
  }

 if (val>=25 && val<=100){
    digitalWrite(led2,HIGH);
    digitalWrite(led1,HIGH);
  delay(100);                  //slight delay to minimize flickering
}
  else{
    digitalWrite(led2,LOW);
    digitalWrite(led1,LOW);
  }
if (val>=0 && val<=25){
    digitalWrite(led1,HIGH);
 delay(100);                   //slight delay to minimize flickering
}
  else{
    digitalWrite(led1,LOW);
  }
}