Task 26:
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading
// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
Serial.println(" - Dim");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
}
delay(1000);
}
Task 27:
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
int ledPin13 = 13;
int ledPin12 = 12;
int ledPin11 = 11;
int ledPin10 = 10;
int counter;
void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin10, OUTPUT);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading
// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
//Serial.println(" - Dim");
digitalWrite(ledPin13, HIGH);
//delay(1000);
digitalWrite(ledPin12, LOW);
digitalWrite(ledPin11, LOW);
for(counter = 1; counter < 50; counter++) {
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin13, LOW);}
} else if (photocellReading < 500) {
//Serial.println(" - Light");
digitalWrite(ledPin12, HIGH);
//delay(1000);
digitalWrite(ledPin11, LOW);
digitalWrite(ledPin13, LOW);
} else if (photocellReading < 800) {
//Serial.println(" - Bright");
digitalWrite(ledPin11, HIGH);
//delay(1000);
digitalWrite(ledPin12, LOW);
digitalWrite(ledPin13, LOW);
} else {
//Serial.println(" - Very bright");
}
delay(0);
}
Sunday, May 2, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment