diff --git a/wtf/wtf.ino b/wtf/wtf.ino index 86e0aa9..2fd2372 100644 --- a/wtf/wtf.ino +++ b/wtf/wtf.ino @@ -1,16 +1,36 @@ +#include #include #include #include - LiquidCrystal lcd(9, 3, 8, 7, 6, 5, 4); Encoder rotEnc(A0, A1); long encVal = 0; int activeTimer=0; int timerLens[3]; -int grindCheck = 0; bool updateDisplay=false; +int eeAddr1 = 0; +int eeAddr2 = 5; +int eeAddr3 = 10; + + +void EEPROMWriteInt(int p_address, int p_value) { + byte lowByte = ((p_value >> 0) & 0xFF); + byte highByte = ((p_value >> 8) & 0xFF); + + EEPROM.write(p_address, lowByte); + EEPROM.write(p_address + 1, highByte); +} + +unsigned int EEPROMReadInt(int p_address) { + byte lowByte = EEPROM.read(p_address); + byte highByte = EEPROM.read(p_address + 1); + + return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00); +} + + bool buttonLeftPressed=false; void buttonLeft() { buttonLeftPressed=true; @@ -55,7 +75,7 @@ void grind(int time) { delay(time); digitalWrite(2, LOW); lcdPut("Fin..."); - delay(750); + delay(550); updateDisplay=true; } @@ -72,17 +92,24 @@ void boilerplate() { return; } - if( digitalRead(A2) == LOW && grindCheck > 17500 ) { + if( digitalRead(A2) == LOW) { + + for(int i=0; i<10; i++) { + if( digitalRead(A2) != LOW ) + return; + delay(150); + } + + pinMode(A2, INPUT); + digitalWrite(A2, LOW); + grind( timerLens[activeTimer] ); - grindCheck = 0; + + pinMode(A2, INPUT); + digitalWrite(A2, HIGH); + delay(25); } - if( digitalRead(A2) == LOW && grindCheck >= 0 && grindCheck <= 17500 ) { - grindCheck++; - } - if( digitalRead(A2) == HIGH && grindCheck > 0 ) { - grindCheck = 0; - } if( digitalRead(A3) == LOW ) { @@ -143,6 +170,13 @@ void loop() { sprintf(str, "T%1d:%5d", activeTimer, timerLens[activeTimer]); lcdPut(str); updateDisplay=false; + + if(EEPROMReadInt(eeAddr1) != timerLens[0]) + EEPROMWriteInt(eeAddr1, timerLens[0]); + if(EEPROMReadInt(eeAddr2) != timerLens[1]) + EEPROMWriteInt(eeAddr2, timerLens[1]); + if(EEPROMReadInt(eeAddr3) != timerLens[2]) + EEPROMWriteInt(eeAddr3, timerLens[2]); } } @@ -153,10 +187,16 @@ void setup() { //Serial.begin(9600); - timerLens[0] = 1000; - timerLens[1] = 250; - timerLens[2] = 9950; - +// EEPROMWriteInt(eeAddr1, 4500); +// EEPROMWriteInt(eeAddr2, 500); +// EEPROMWriteInt(eeAddr3, 10000); + + timerLens[0] = EEPROMReadInt(eeAddr1); + timerLens[1] = EEPROMReadInt(eeAddr2); + timerLens[2] = EEPROMReadInt(eeAddr3); + + pinMode(A2, INPUT); + digitalWrite(A2,HIGH); pinMode(A3, INPUT); digitalWrite(A3,HIGH); pinMode(A4, INPUT); @@ -167,5 +207,9 @@ void setup() pinMode(2, OUTPUT); digitalWrite(2, LOW); + lcd.clear(); lcd.home(); + lcd.print("INIT"); + delay(2500); + updateDisplay=true; }