From 33519c4311b79951aa2a08a86eec53935c43b8bd Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Wed, 14 Aug 2013 00:16:18 +0200 Subject: [PATCH] eeprom try1 --- wtf/wtf.ino | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/wtf/wtf.ino b/wtf/wtf.ino index 267940a..a6c35bb 100644 --- a/wtf/wtf.ino +++ b/wtf/wtf.ino @@ -1,8 +1,9 @@ +#include + #include #include #include - LiquidCrystal lcd(9, 3, 8, 7, 6, 5, 4); Encoder rotEnc(A0, A1); long encVal = 0; @@ -11,6 +12,27 @@ 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 +77,7 @@ void grind(int time) { delay(time); digitalWrite(2, LOW); lcdPut("Fin..."); - delay(750); + delay(550); } @@ -142,6 +164,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]); } } @@ -152,9 +181,14 @@ 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(A3, INPUT); digitalWrite(A3,HIGH);