Imagine | Develop | Create
#include <LiquidCrystal.h> #include <RGB_LED.h> #define upButtonPin A0 #define downButtonPin A1 #define modeButtonPin A2 byte mode = 1; unsigned int speed = 1000; byte DMX = 1; LiquidCrystal lcd(2, 4, 5, 6, 7, 8); RGB_LED LED(3,10,11); void setup() { Serial.begin(9600); lcd.begin(16, 2); pinMode(upButtonPin,INPUT); pinMode(downButtonPin,INPUT); pinMode(modeButtonPin, INPUT); Serial.println("Start"); changemode(); setsetting(); } void loop() { LED.run(); if(mode ==6) { DMXcontrol(); } if(digitalRead(modeButtonPin)==HIGH) { mode++; changemode(); setsetting(); controldelay(); // and mode button is low } if(digitalRead(upButtonPin)==HIGH) { upsetting(); setsetting(); controldelay(); } if(digitalRead(downButtonPin)==HIGH) { downsetting(); setsetting(); controldelay(); } } void changemode() { lcd.setCursor(0,0); Serial.println(mode); switch(mode) { case 1: Serial.println("Fade"); lcd.print("Fade"); LED.setFunction(Fade); break; case 2: Serial.println("Fade Random"); lcd.print("Fade Random"); LED.setFunction(FadeRandom); break; case 3: Serial.println("Step RGB"); lcd.print("Step RGB"); LED.setFunction(Step1); break; case 4: Serial.println("Step ALL"); lcd.print("Step ALL"); LED.setFunction(Step2); break; case 5: Serial.println("Step Random"); lcd.print("Step Random"); LED.setFunction(StepRandom); break; case 6: Serial.println("DMX"); lcd.print("DMX"); LED.fadeToColour(Black,500); break; case 7: Serial.println("White"); lcd.print("White"); LED.fadeToColour(White,500); break; case 8: Serial.println("Red"); lcd.print("Red"); LED.fadeToColour(Red,500); break; case 9: Serial.println("Gre"); lcd.print("Green"); LED.fadeToColour(Green,500); break; case 10: Serial.println("Blue"); lcd.print("Blue"); LED.fadeToColour(Blue,500); break; default: mode = 1; changemode(); } lcd.print(" "); } void setsetting() { lcd.setCursor(0,1); if(mode <=5) { lcd.print("Speed: "); lcd.print(speed); LED.setSpeed(speed); } else if(mode ==6) { lcd.print("Address: "); lcd.print(DMX); } lcd.print(" "); } void upsetting() { if(mode <=5 && speed < 30000) { speed = speed +100; } else if(mode ==6 && DMX < 255) { DMX++; } } void downsetting() { if(mode <=5 && speed > 100) { speed = speed - 100; } else if(mode ==6 && DMX > 1) { DMX--; } } void controldelay() { unsigned long currenttime = millis(); while(currenttime+50 > millis() || digitalRead(modeButtonPin)==HIGH) { LED.run(); } } void DMXcontrol() { }