diff --git a/arduino-mixer.ino b/arduino-mixer.ino index 9360aff..86ccf1e 100644 --- a/arduino-mixer.ino +++ b/arduino-mixer.ino @@ -10,13 +10,26 @@ Adafruit_PCD8544 display = Adafruit_PCD8544(14, 15, 16, 17, 18); Button button(4); Encoder encoder(3, 2); +// General vars unsigned long time; int connected = 0; int editing = 0; int blink = 0; +// Encoder related vars long position = 0; +// Serial related vars +const byte numChars = 32; +char receivedChars[numChars]; +char tempChars[numChars]; + +char command[numChars] = {0}; +char data[numChars] = {0}; +int intData = 0; + +boolean newData = false; + // Set backlight int light = 0; @@ -35,11 +48,12 @@ void toggleBacklight(int value = 128) { // Set variables for menu int programLenght; int currentProgram = 0; +char programName[numChars] = {0}; int menuUpdate = 1; -int volume; +float volume; // Draw screen -void drawMenu(String name, float percentage) { +void drawMenu(char name, float percentage) { display.clearDisplay(); display.setFont(&Picopixel); @@ -139,7 +153,8 @@ void drawBar(float percentage) { } // Draw program name in the middle of the display or scroll it -void drawName(String name) { +// TODO: Fix char lenght +void drawName(char name) { int width = name.length() * 6; if (width > 84) { @@ -152,6 +167,7 @@ void drawName(String name) { } // Check for button input +// TODO: Improve encoder input void checkInput(unsigned long time) { long newPosition = encoder.read(); if (newPosition != position) { @@ -194,16 +210,6 @@ void checkInput(unsigned long time) { } } -const byte numChars = 32; -char receivedChars[numChars]; -char tempChars[numChars]; - -char command[numChars] = {0}; -char data[numChars] = {0}; -int intData = 0; - -boolean newData = false; - void processData() { if (newData == true) { Serial.print("Raw data recieved: "); @@ -222,8 +228,29 @@ void processData() { if (atoi(strtokIndx) > 0) // Integer data { intData = atoi(strtokIndx); + Serial.print("Int data: "); + Serial.println(intData); } else { // String data strcpy(data, strtokIndx); + Serial.print("String data: "); + Serial.println(data); + } + + if (strcmp("HELLO", command) == 0) + { + Serial.println(""); + } + else if (strcmp("COUNT", command) == 0) + { + programLenght = intData; + } + else if (strcmp("NAME", command) == 0) + { + // Set program name + } + else if (strcmp("GETVOL", command) == 0) + { + // Set volume } newData = false; @@ -300,19 +327,7 @@ void loop() { // Draw menu every second or every 0.1 second when editing if (menuUpdate == 1 || (editing == 1 && time % 100 == 0)) { menuUpdate = 0; - // TODO: Get serial data for program - switch (currentProgram) - { - case 0: - drawMenu("Firefox", volume); - break; - case 1: - drawMenu("Discord", volume); - break; - case 2: - drawMenu("Steam", volume); - break; - } + drawMenu(programName, volume); } // Check input