/* DNA Lamp */ int led = 9; // the pin that the LEDs are attached to int button = 8; // the pin that the button is connected to int motor = 11; // the pin that the relay for the motor is attached to int mode=0; // initial operation mode int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by // the setup routine runs once when you press reset: void setup() { pinMode(led, OUTPUT); // declare pin 9 to be an output: pinMode(motor, OUTPUT); // declare pin 11 to be an output: pinMode(button, INPUT_PULLUP); // declare pin 8 to be an input with internal pullups: } // the loop routine runs over and over again forever: void loop() { if (digitalRead(button)==LOW) //changes operation mode when switch is pressed { if (mode!=5) { mode=mode+1; } else { mode=0; } delay(1500); //time to wait between push button can be pressed again } if (mode==0) //LEDs fading and rotation motor ON { // set the brightness of pin 9: analogWrite(led, brightness); if (brightness==0) { delay(500); //time while fading that LEDs will be off } // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } // wait for 30 milliseconds to see the dimming effect delay(30); digitalWrite(motor, 1); } else if (mode==1) //LEDs fading and rotation motor OFF { // set the brightness of pin 9: analogWrite(led, brightness); if (brightness==0) { delay(1000); } // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } // wait for 30 milliseconds to see the dimming effect delay(30); digitalWrite(motor, 0); } else if (mode==2) //LEDs ON and rotation motor ON { digitalWrite(motor, 1); digitalWrite(led, 1); } else if (mode==3) //LEDs ON and rotation motor OFF { digitalWrite(motor, 0); digitalWrite(led, 1); } else if (mode==4) //LEDs OFF and rotation motor ON { digitalWrite(motor, 1); digitalWrite(led, 0); } else if (mode==5) //LEDs OFF and rotation motor OFF { digitalWrite(motor, 0); digitalWrite(led, 0); } }