// Analog pin settings int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2 int bIn = 1; // (Connect power to 5V and ground to analog ground) int cIn = 2; //int PhotoIn = 4; // photoresistor connected to analog 4 pin // Digital pin settings int aOut = 9; // red LEDs connected to digital pins 9, 10 and 11 int bOut = 10; // blue (Connect cathodes to digital ground) int cOut = 11; //green int inBlink = 6; //switch connected to digital 6 int inTouch = 2; // pushbutton/touchsensor connected to digital 2 // Values int aVal = 0; // Variables to store the input from the potentiometers int bVal = 0; int cVal = 0; int TouchSensor_Val = 0; // variable for reading the touch sensor/pushbutton pin status int BlinkButton_Val = 0; //variable for reading the 2nd button/switch that controls blinking // Variables for comparing values between loops int i = 0; // Loop counter int wait = (1000); // Delay between most recent pot adjustment and output int checkSum = 0; // Aggregate pot values int prevCheckSum = 0; int sens = 3; // Sensitivity theshold, to prevent small changes in // pot values from triggering false reporting // FLAGS int PRINT = 1; // Set to 1 to output values int DEBUG = 1; // Set to 1 to turn on debugging output void setup() { pinMode(aOut, OUTPUT); // declare LED as output pinMode(bOut, OUTPUT); pinMode(cOut, OUTPUT); pinMode(inTouch, INPUT); // declare pushbutton as input pinMode(inBlink, INPUT); // declare photoresistor as input Serial.begin(9600); //open serial port; data rate at 9600 bps } void loop(){ i += 1; // Count loop BlinkButton_Val = digitalRead(inBlink); // read input value TouchSensor_Val = digitalRead(inTouch); // read input value aVal = analogRead(aIn) / 4; // read input pins, convert to 0-255 scale bVal = analogRead(bIn) / 4; cVal = analogRead(cIn) / 4; if (TouchSensor_Val == LOW) { // check if the input is LOW (button pressed) pulse change the color for(aVal = 0; aVal <=255; aVal+=5) { analogWrite(aOut, aVal); // Send new values to LEDs delay(100); } for(bVal = 0; bVal <=255; bVal+=5) { analogWrite(bOut, bVal); // Send new values to LEDs delay(100); } for(cVal = 0; cVal <=255; cVal+=5) { analogWrite(cOut, cVal); // Send new values to LEDs delay(100); } } else if (BlinkButton_Val == LOW) { //check if the input is LOW (button pressed) blink analogWrite(aOut, 0); // Send new values to LEDs analogWrite(bOut, bVal); analogWrite(cOut, cVal); delay(5000); analogWrite(aOut, aVal); analogWrite(bOut, 0); analogWrite(cOut, cVal); delay(5000); //delay for the time of the photoresistor var. reading analogWrite(aOut, aVal); analogWrite(bOut, bVal); analogWrite(cOut, 0); delay(5000); } else { //if button is released LEDs can be manually manipulated analogWrite(aOut, aVal); // Send new values to LEDs analogWrite(bOut, bVal); analogWrite(cOut, cVal); } // TouchSensor_Val = Serial.read(); //Photo_Val = analogRead(4); // read analog input from pin 4 // Serial.print("Photo_Val: "); //print the string // Serial.print(Photo_Val, DEC); // print the value read // Serial.print("\t"); // print a space between the readings // delay(100); // wait 100ms for next reading }