diff --git a/Maybe/Maybe.ino b/Maybe/Maybe.ino index 60ec6a6..3f8b96e 100644 --- a/Maybe/Maybe.ino +++ b/Maybe/Maybe.ino @@ -30,7 +30,8 @@ MemSlot memory[] = //128 bytes for the Teensy LC {"bt10", 11, 0}, {"bt11", 12, 0}, {"bt12", 13, 0}, - {"reset", 0, 0}, //255 = reset eeprom + {"effc", 14, 1}, + {"reset", 0, 0}, // != 0 -> reset eeprom }; @@ -50,6 +51,7 @@ MenuItem menuEntries[] = { {"", true, "prst"}, {"", false, "butt"}, + {"", true, "effc"}, {"", true, "reset"}, {"/butt", true, "bt1"}, {"/butt", true, "bt2"}, @@ -138,6 +140,7 @@ bool animationPlaying = false; unsigned int animationLastFrameMillis = 0; unsigned int animationFrameDelayMillis = 64; bool animationLooping = false; +bool animationEnabled = true; /* * time cooldown managment @@ -155,32 +158,13 @@ unsigned int sevSegCoolDown = 5000; Serial.begin(9600); Serial.println("setup start"); - //write eeprom first init - byte memValue = EEPROM.read(0); - if (memValue == 255) // cannot find settings, writes defualt ones - { - for (byte i = 0; i < (sizeof(memory)/sizeof(MemSlot)); i++) - { - EEPROM.write(memory[i].address, memory[i].value); - } - EEPROM.write(0,1); - } - //read eeprom - for (byte i = 0; i < (sizeof(memory)/sizeof(MemSlot)); i++) - { - memory[i].value = EEPROM.read(memory[i].address); - } + //memory + initEepromMemory(); - //Init display - byte numDigits = 4; - byte digitPins[] = {7, 8, 9, 6}; - byte segmentPins[] = {10, 12, 14, 16, 17, 11, 13, 15}; + applyMemoryChange(); - bool resistorsOnSegments = true; - //bool updateWithDelaysIn = true; - byte hardwareConfig = COMMON_CATHODE; - sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments); - sevseg.setBrightness(90); + //display + initSevSegDisplay(); //Init rotary encoders rotaryEncoder.setDebounceDelay(2); @@ -200,13 +184,46 @@ unsigned int sevSegCoolDown = 5000; } +void initEepromMemory() +{ + //write eeprom first init + byte memValue = EEPROM.read(0); + if (memValue > 0) // cannot find settings, writes default ones + { + for (byte i = 0; i < (sizeof(memory)/sizeof(MemSlot)); i++) + { + EEPROM.write(memory[i].address, memory[i].value); + } + EEPROM.write(getMemorySlot("reset")->address,0); + } + //read eeprom + for (byte i = 0; i < (sizeof(memory)/sizeof(MemSlot)); i++) + { + memory[i].value = EEPROM.read(memory[i].address); + } +} + +void initSevSegDisplay() +{ + //Init display + byte numDigits = 4; + byte digitPins[] = {7, 8, 9, 6}; + byte segmentPins[] = {10, 12, 14, 16, 17, 11, 13, 15}; + + bool resistorsOnSegments = true; + //bool updateWithDelaysIn = true; + byte hardwareConfig = COMMON_CATHODE; + sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments); + sevseg.setBrightness(90); +} + /* * Tick Loop */ void loop() { //animation draw tick - if (animationPlaying && millis() > (animationLastFrameMillis + animationFrameDelayMillis)) + if (animationEnabled && animationPlaying && millis() > (animationLastFrameMillis + animationFrameDelayMillis)) { drawAnimation(animationLooping); animationLastFrameMillis = millis(); @@ -306,7 +323,7 @@ void menuBack() isInMenu = false; menuSelectionIndex = 0; menuCurrentPath = ""; - sevseg.blank(); + playAnimation(3); } else { @@ -400,11 +417,17 @@ bool menuSetValue(String variableName, byte newValue) if (memorySlot != NULL) { memorySlot->value = newValue; + applyMemoryChange(); return true; } return false; } +void applyMemoryChange() +{ + animationEnabled = (getMemorySlot("effc")->value > 0); +} + int menuGetSelectionIndexFromPath(String path) { int correspondingPathItemIndex = 0; @@ -480,7 +503,7 @@ void sendInputOuput(int input) if (isInMenu) { menuBack(); - playAnimation(3); + //playAnimation(3); } else {