#include #include const int photoA = 2; // Connect the phototransistor to the analog input pin const int photoB = 8; // Connect the phototransistor to the analog input pin const int ledPin = 9; // Connect the LED to digital pin 9 const int buttonPin = 0; // connect to button int buttonState= LOW; // create buttonState variable int lastButtonState = LOW; // create a lastButtonState variable int pos= 0; // Create a servo variable and set to zero Servo myservo; // create servo object to control a servo void setup() { pinMode(ledPin, OUTPUT); // Set the LED pin as an output pinMode(buttonPin, INPUT); // Set button pin as input myservo.attach(3); // attaches the servo on pin 9 to the servo object } void loop() { int lightLevel1 = analogRead(photoA); // Read the analog value from the phototransistor int lightLevel2 = analogRead(photoB); // Read the analog value from the phototransistor int buttonRead= digitalRead(buttonPin); // Read the state of the button if (buttonRead != lastButtonState){ // Compare button position delay(50); // Debounce buttonRead = digitalRead(buttonPin); } if (buttonRead != lastButtonState) { // check button position buttonState = buttonRead; } if (lightLevel1 < lightLevel2) { // Compare light level myservo.write(pos=180); } else if (lightLevel2 < lightLevel1 ){ Compare light level myservo.write(pos=0); } if (buttonState == HIGH) { // Compare button position digitalWrite(ledPin,! digitalRead(ledPin)); } lastButtonState = buttonRead; delay(150); // Debounce }