Thursday, March 18, 2010

Task 38 - Program to output the value of your LDR whenever you press the button.

//Program to output the value of your LDR whenever you press the button.

int buttonPin = 2; // the number of the pushbutton pin
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}

void loop(){

photocellReading = analogRead(photocellPin);
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
Serial.print("Analog reading = ");
Serial.println(photocellReading);
delay(500);
}
else {
buttonState == LOW;
}
}

No comments:

Post a Comment