The sketch
int photocellPin1 = 1; // the cell and 10K pulldown are connected to a1 int photocellReading1; // the analog reading from the sensor divider int motor1 = 2; // connect motor to pin D2 int photocellPin2 = 2; int photocellReading2; int motor2 = 3; void setup() { pinMode(motor1, OUTPUT); pinMode(motor2, OUTPUT); Serial.begin(9600); } void pca() { photocellReading1 = analogRead(photocellPin1); if (photocellReading1 <=500){ digitalWrite(motor1, HIGH); } else { digitalWrite(motor1, LOW); } } void pcb() { photocellReading2 = analogRead(photocellPin2); if (photocellReading2 <=500){ digitalWrite(motor2, HIGH); } else { digitalWrite(motor2, LOW); } } void loop() { pca(); pcb(); delay(50); } |
No comments:
Post a Comment