// declare variables:
int switchPin01 = 1; //small photocell
int switchPin02 = 2; //large photocell
int yellowLedPin = 3; // digital output pin for an LED
int redLedPin = 4; // digital output pin for an LED
int switchState01 = 0; // the state of the switch
int switchState02 = 0; // the state of the switch
void setup() {
pinMode(switchPin01, INPUT);
pinMode(switchPin02, INPUT); // set the switch pin to be an input
pinMode(yellowLedPin, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLedPin, OUTPUT); // set the red LED pin to be an output
}
void loop() {
// read the switch input:
switchState01 = digitalRead(switchPin01);
switchState02 = digitalRead(switchPin02);
//covered (0), not(1) – then yellow
if (switchState01 == 0 && switchState02 == 0) {
// if the switch is closed:
digitalWrite(yellowLedPin, HIGH); // turn on the yellow LED
digitalWrite(redLedPin, LOW); // turn off the red LED
}
else {
// if the switch is open:
digitalWrite(yellowLedPin, LOW); // turn off the yellow LED
digitalWrite(redLedPin, HIGH); // turn on the red LED
}
}
Tags: arduino · sensor · switchNo Comments
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.