const int R_PIN = 6; const int G_PIN = 5; const int B_PIN = 9; const int SWITCH_PIN= 8; const int BUTTON_PIN = 3; const int POT_1_PIN = 18; int POT_1_VAL = 0; int DELAY = 10; int lastValue = 0; int colorValue = 0; int stepValue = 1; int directionFlag = 1; void setup() { delay(1000); // some microcontrollers reboot twice // Serial.begin(115200); // while (! Serial); // Wait until Serial is ready - Leonardo/Micro // Serial.println(F("setup(): begin")); pinMode(R_PIN, OUTPUT); pinMode(G_PIN, OUTPUT); pinMode(B_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(SWITCH_PIN, INPUT_PULLUP); } void loop() { // POT_1_VAL = analogRead(POT_1_PIN); // Serial.println(POT_1_VAL); int buttonState = digitalRead(BUTTON_PIN); int switchState = digitalRead(SWITCH_PIN); Serial.println(buttonState); // set color direction stepValue = 5; if (colorValue <= 0) { directionFlag = 1; } else if (colorValue >= 255) { directionFlag = -1; } DELAY = 100; colorValue = colorValue + (stepValue * directionFlag); // FIRE!!!!! if(buttonState == 0) { DELAY = 15; RGB_color(0, 255, 255); // GREEN delay(DELAY); RGB_color(255, 0, 255); // BLUE delay(DELAY); RGB_color(255, 255, 0); // RED delay(DELAY); // RGB_color(255, 255, 255); // OFF // delay(DELAY); // ARMED!!! } else if(switchState == 0) { RGB_color(255, 255, colorValue); // RED } else { // RGB_color(0, 255, 255); // GREEN // delay(DELAY); RGB_color(255, colorValue, 255); // BLUE // delay(DELAY); // RGB_color(255, 255, 0); // RED // delay(DELAY); // RGB_color(255, 255, 255); // OFF // delay(DELAY); } delay(10); } void RGB_color(int red_light_value, int green_light_value, int blue_light_value) { analogWrite(R_PIN, red_light_value); analogWrite(G_PIN, green_light_value); analogWrite(B_PIN, blue_light_value); }