// ########## DMX Sheet ##########
// ########## Mode 1 ##########
// 6 dmx channel
// ch1 - Dimmer
// ch2 - Red
// ch3 - Green
// ch4 - Blue
// ch5 - Pan
// ch6 - Panless Rot (0, 255 Stop, 1 - 127 Rotate clockwise (slow to fast), 128 - 254 Rotate anti-clockwise (slow to fast))
#include <elapsedMillis.h>
#include <LiquidCrystal_I2C.h>
#include <FastLED.h>
//Timer setup
elapsedMillis timerDef;
elapsedMillis menuExit;
elapsedMillis screenOut;
//Add LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
//LED config
#define NUM_LED 6
#define LED_PIN 2
CRGB leds[NUM_LED];
//Navigation button varibles
int menuBtn = 0;
int upBtn = 0;
int downBtn = 0;
int enterBtn = 0;
//Operation varibles
int dmxAddres = 1;
bool dmxStatus = false;
bool dmxEnable = true;
int menuPos = 1;
int dmxMode = 1;
int screenTime = 0;
bool btnAccess = true;
bool reset = false;
void setup() {
//Initalise the LCD
lcd.init();
lcd.backlight();
lcd.print(" STARTING");
//Setup LED
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LED);
FastLED.setBrightness(255);
//Setup navigation buttons
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
}
void loop() {
//Reser fixture to home pos
//Select mode after reset
switch(dmxMode) {
case 1:
mode1();
break;
case 2:
mode2();
break;
case 3:
mode3();
break;
}
}
void menu() {
while(true) {
if(timerDef > 50) {
menuBtn = analogRead(A0);
upBtn = analogRead(A1);
downBtn = analogRead(A2);
enterBtn = analogRead(A3);
//Disabled action if button on hold
if(menuBtn > 200 && upBtn > 200 && downBtn > 200 && enterBtn > 200) { btnAccess = true; }
//Menu scroll up
if(upBtn < 200 && btnAccess == true) {
btnAccess = false;
if(menuPos == 1) {
menuPos = 4;
menuDraw();
break;
} else {
menuPos = menuPos - 1;
menuDraw();
break;
}
}
//Menu scroll down
if(downBtn < 200 && btnAccess == true) {
btnAccess = false;
if(menuPos == 4) {
menuPos = 1;
menuDraw();
break;
} else {
menuPos = menuPos + 1;
menuDraw();
break;
}
}
//Enter selected menu
if(enterBtn < 200 && btnAccess == true) {
}
//Exit from menu
if(menuBtn < 200 && btnAccess == true) {
menuPos = 1;
switch(dmxMode) {
case 1:
btnAccess = false;
mode1();
break;
case 2:
btnAccess = false;
mode2();
break;
case 3:
btnAccess = false;
mode3();
break;
}
}
timerDef = 0;
}
}
}
void menuDraw() {
switch(menuPos) {
case 1: //DMX addres
lcd.clear();
lcd.setCursor(0,0);
lcd.print("DMX Address");
lcd.setCursor(0,1);
if(dmxAddres < 10) {
lcd.print("00" + String(dmxAddres));
} else if (dmxAddres < 100) {
lcd.print("0" + String(dmxAddres));
}
menu();
break;
case 2: //DMX mode
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Mode");
lcd.setCursor(0,1);
lcd.print(String(dmxMode));
menu();
break;
case 3: //Display timeout
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Screen Time");
lcd.setCursor(0,1);
lcd.print(String(screenTime));
menu();
break;
case 4: //Manual control
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Manual Mode");
menu();
break;
}
}
void manualControl() {
}
void mode1() {
lcd.clear();
lcd.setCursor(7,0);
if(dmxAddres < 10) {
lcd.print("00" + String(dmxAddres));
} else if (dmxAddres < 100) {
lcd.print("0" + String(dmxAddres));
}
lcd.setCursor(7,1);
lcd.print("M:1");
while(true) {
if(timerDef > 50) {
menuBtn = analogRead(A0);
upBtn = analogRead(A1);
downBtn = analogRead(A2);
enterBtn = analogRead(A3);
//Disabled action if button on hold
if(menuBtn > 200 && upBtn > 200 && downBtn > 200 && enterBtn > 200) { btnAccess = true; }
//Enter menu
if(menuBtn < 200 && btnAccess == true) { btnAccess = false; menuDraw(); break;}
timerDef = 0;
}
}
}
void mode2() {
}
void mode3() {
}