#define DEBUG_ENABLED
#include <LiquidCrystal.h>
/*
Tutaj jedynie podstawka pod kontroler dmx
być może nawet nadawacz DMX jak programy oświetleniowe
nie będą trudne do implementacji
Można pobawić się joystickiem
z czasem dodam aby przewijanie było szybkie i płynne
zamiast na zmianę stanu
*/
#define CONFIG_PIN 8
#ifdef DEBUG_ENABLED
#define DEBUG_PRINT(value) Serial.print(value)
#define DEBUG_PRINTLN(value) Serial.println(value)
#else
#define DEBUG_PRINT(value)
#define DEBUG_PRINTLN(value)
#endif
// LCD
#define lcd_rs 13
#define lcd_enable 12
#define lcd_d4 7
#define lcd_d5 6
#define lcd_d6 5
#define lcd_d7 4
LiquidCrystal lcd(lcd_rs, lcd_enable, lcd_d4, lcd_d5, lcd_d6, lcd_d7);
// Joystick
#define VERT_PIN A3
#define HORZ_PIN A4
#define SEL_PIN 3
int dmxOffset = 0;
// DMX
int currentUniverse = 1;
const int numUniverses = 32;
uint8_t universeDB[numUniverses];
uint8_t dmxData[numUniverses][512];
void setup() {
#ifdef DEBUG_ENABLED
Serial.begin(115200);
#endif
// Get settings from EEPROM
InitSettings();
// Initialize the LCD
InitLCD();
//Initialize the control scheme
InitJoystick();
PrintUI();
}
int joystickState = 0;
// 0 - nullState
// 1 - TOP
// 2 - BOTTOM
// 3 - RIGHT
// 4 - LEFT
bool buttonState = false;
uint8_t buttonBounce = 0;
// 0 - nullState
// 1 - button was pressed
void InitSettings()
{
// TODO: Load setting from EEPROM
}
void SaveSettings()
{
// TODO: Add a saving feature to EEPROM
}
void PrintUI()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ARDUINO: ");
lcd.print(currentUniverse);
lcd.setCursor(0,1);
lcd.print("UNIVERSE: ");
if(universeDB[currentUniverse-1] == 0)
{
lcd.print("OFF");
}
else
{
lcd.print(universeDB[currentUniverse-1]);
}
// TODO: Rewrite the joystick and LCD control to create an UI for:
// 1. Switching a DMX output ON/OFF
// 2. Assigning the IP address of the device
// 3. Assigning any universe from the 32 offset pool to any DMX pin
// 4. Offsetting what universe to watch ()
}
void InitLCD()
{
lcd.begin(16, 2);
}
void InitJoystick()
{
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
}
void processJoystick()
{
int horz = analogRead(HORZ_PIN);
int vert = analogRead(VERT_PIN);
bool button = digitalRead(SEL_PIN) == LOW;
if (horz > 1019 && vert < 515 && vert > 509)
{
joystickState = 4;
return;
}
else if (horz < 32 && vert < 515 && vert > 509)
{
joystickState = 3;
return;
}
else if (horz < 515 && horz > 509 && vert > 1019)
{
joystickState = 1;
return;
}
else if (horz > 509 && horz < 515 && vert < 32)
{
joystickState = 2;
return;
}
else
{
switch (joystickState)
{
case 1:
DEBUG_PRINTLN("JOYSTICK: UP");
universeDB[currentUniverse-1]++;
if (universeDB[currentUniverse-1] > 255)
{
universeDB[currentUniverse-1] = 0;
}
PrintUI();
break;
case 2:
DEBUG_PRINTLN("JOYSTICK: DOWN");
universeDB[currentUniverse-1]--;
if (universeDB[currentUniverse-1] < 0)
{
universeDB[currentUniverse-1] = 255;
}
PrintUI();
break;
case 3:
DEBUG_PRINTLN("JOYSTICK: RIGHT");
currentUniverse++;
if (currentUniverse > numUniverses)
{
currentUniverse = 1;
}
PrintUI();
break;
case 4:
DEBUG_PRINTLN("JOYSTICK: LEFT");
currentUniverse--;
if (currentUniverse < 1)
{
currentUniverse = numUniverses;
}
PrintUI();
break;
}
joystickState = 0;
}
if (button)
{
buttonState = true;
buttonBounce = 1;
return;
}
else
{
if (buttonBounce == 0)
{
if (buttonState)
{
DEBUG_PRINTLN("JOYSTICK: Button was released");
buttonState = false;
return;
}
}
buttonBounce++;
}
}
void loop() {
processJoystick();
}