Thursday, March 18, 2010

Task 39 - Same As Task 38 With Different Output

//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
int count = 1;

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("Reading number ");
Serial.print(count);
Serial.print(": ");
Serial.println(photocellReading);
delay(500);
count++;
}
else {
buttonState == LOW;
}
}

No comments:

Post a Comment