Wednesday, October 7, 2009

Analog Pin

int ledPinOne = 10; //setting up variables for all three LEDs
int ledPinTwo = 6;
int ledPinThree = 2;

const int analogPin = 0; //for the flex sensor
const int flex = 100; //value

void setup() {

pinMode(ledPinOne, OUTPUT);//setting up all three LEDs to be outputs
pinMode(ledPinTwo, OUTPUT);
pinMode(ledPinThree, OUTPUT);

Serial.begin(9600);
}

void loop()
{

int analogValue = analogRead(analogPin);

if (analogValue > flex) { //if when reading the flex it becomes larger then the value of 100, then //do this
digitalWrite(ledPinOne, HIGH); //light it up
delay(100); //wait 100 millaseconds
}

else { //or if else turn it off and wait 100 millaseconds, and same for the other two LEDs
digitalWrite(ledPinOne,LOW);
delay(100);
}

if (analogValue > flex) {
digitalWrite(ledPinTwo, HIGH);
delay(200);
}
else {
digitalWrite(ledPinTwo,LOW);
delay(200);
}

if (analogValue > flex) {
digitalWrite(ledPinThree, HIGH);
delay(400);
}
else {
digitalWrite(ledPinThree,LOW);
delay(400);
}



Serial.println(analogValue, DEC); //print it


}

No comments:

Post a Comment