Unit 13: A touching connection
Code for Sketch:
const int touchSensor1 = 12; // Touch sensor 1 pin
const int touchSensor2 = 13; // Touch sensor 2 pin
const int redLED = 6; // Red LED pin
const int greenLED = 7; // Green LED pin
void setup() {
pinMode(touchSensor1, INPUT);
pinMode(touchSensor2, INPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
}
void loop() {
bool touch1 = digitalRead(touchSensor1) == HIGH;
bool touch2 = digitalRead(touchSensor2) == HIGH;
if (touch1 && touch2) {
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
} else if (touch1 || touch2) {
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
} else {
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
}
}