Adventures in Arduino by Becky Stewart

Page 107

Serial.println("Turn on yellow, turn off green and red"); // turn on yellow LED digitalWrite(yellowLED, HIGH); // turn off green and red LEDs digitalWrite(greenLED, LOW); digitalWrite(redLED, LOW); } // if pot more than or equal to 682 if(potValue >= 682) { Serial.println("Turn on red, turn off green and yellow."); // turn on red LED digitalWrite(redLED, HIGH); // turn off green and yellow LEDs digitalWrite(greenLED, LOW); digitalWrite(yellowLED, LOW); } }

Upload the sketch with the circuit on the breadboard. If you don’t want to type all the code, you can download the sketch from the companion site at www.wiley.com/go/adventuresinarduino. Ready? Time to try it out. You should be able to change which LED turns on by turning the potentiometer. Only one LED should turn on at a time. You can open the Serial Monitor in the Arduino IDE to make sure the correct values are coming from the potentiometer.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.