Tuesday, October 27, 2009

Shanna B Exercise #3 (Resistor Light Value)

int ledPin = 9; // Declare pin9 for LED
int photoPin = 1; // variable resistor on analog pin 1
int val = 0;

void setup() // run once, when the sketch starts
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT); // set led pin 9 as OUTPUT
pinMode(photoPin,OUTPUT); // set analog pin 1 as OUTPUT
}

void loop() { // run over and over again
val = analogRead(photoPin); // set val equal to the resistor input

if(val == LOW) {
digitalWrite(ledPin, HIGH);
delay(100);

} else {
digitalWrite(ledPin, LOW);
}
Serial.println(val);
} video

No comments:

Post a Comment