Commits

mindogas committed cb39dbf

Buttons and LEDs handeling update

Comments (0)

Files changed (1)

SolderingStation.ino

 int readings[numReads];      // the readings from the analog input
 int index = 0;                  // the index of the current reading
 int total = 0;                  // the running total
+short int debounceDelay = 200; //keys debounce time
+
+
 
 TM1638 module(2, 4, 3);
 
   targetTemp=EEPROM.read(0)*256+EEPROM.read(1); //reading motor 1 speed
   messageConstr(2, " ", targetTemp, " ", currentTemp); //generaiting display string
   module.setDisplayToString(re); //updating TM1638 display string
-  module.setLEDs(0xFF << 8);
+  setTempLEDs();
 }
 
 void loop() 
     if (currentTemp<targetTemp)
     {
       analogWrite(soldererPin, 255);
-      module.setLEDs(((0x00FF) & 0xFF)); 
+      module.setLEDs(0x0000);
+      setTempLEDs();
+      module.setLED(TM1638_COLOR_RED, 6);
     } 
     else 
     {
       analogWrite(soldererPin, 0);
-      module.setLEDs(0x0000); 
+      module.setLEDs(0x0000);
+      setTempLEDs();
+      module.setLED(TM1638_COLOR_GREEN, 7);
     }
     //analogWrite(soldererPin, Output);
     //module.setLEDs(((0x00FF) & 0xFF<<(8-map(Output, 0, 255, 0, 8)))); 
   byte keyValue = module.getButtons(); 
   if ((keyValue & (1<<0))) 
   {
+    module.setLEDs(0x0);
+    setTempLEDs();
     targetTemp=EEPROM.read(0)*256+EEPROM.read(1); 
     memoryPosition = 1;
+    delay(debounceDelay); 
   }
   else if ((keyValue & (1<<1))) 
   {
+    module.setLEDs(0x0);
+    setTempLEDs();
     targetTemp=EEPROM.read(2)*256+EEPROM.read(3); 
     memoryPosition = 2;
+    delay(debounceDelay); 
   }
   else if ((keyValue & (1<<2)))
   {
+    module.setLEDs(0x0);
+    setTempLEDs();
     targetTemp=EEPROM.read(4)*256+EEPROM.read(5); 
     memoryPosition = 3;
+    delay(debounceDelay); 
   } 
   else if ((keyValue & (1<<3))) 
   {
+    module.setLED(TM1638_COLOR_RED, 3); //turning on button led to indicate its pressed
     if (targetTemp<400)
       targetTemp++;
     else targetTemp=400;
-  } 
+    module.setLEDs(0x0);
+    setTempLEDs();
+  }
   else if ((keyValue & (1<<4))) 
   {
+    module.setLED(TM1638_COLOR_RED, 4); //turning on button led to indicate its pressed
     if (targetTemp>0)
       targetTemp--;
     else targetTemp = 0;
+    delay(debounceDelay); 
+    module.setLEDs(0x0);
+    setTempLEDs();
   }
   else if ((keyValue & (1<<5))) 
   {
+    module.setLED(TM1638_COLOR_RED, 5); //turning on button led to indicate its pressed
     if (memoryPosition==1)
     {
       EEPROM.write(0,targetTemp/256); 
       EEPROM.write(4,targetTemp/256); 
       EEPROM.write(5,targetTemp%256); 
     }
+    delay(debounceDelay); 
+    module.setLEDs(0x0);
+    setTempLEDs();
   } 
   else if ((keyValue & (1<<6))) 
   {
+    module.setLED(TM1638_COLOR_RED, 6); //turning on button led to indicate its pressed
     running = true;
+    module.setLEDs(0x0);
+    setTempLEDs();
   } 
   else if ((keyValue & (1<<7))) 
   {
+    module.setLED(TM1638_COLOR_RED, 7); //turning on button led to indicate its pressed
     running = false;
-    module.setLEDs(0xFF << 8);
     analogWrite(soldererPin, 0);
+    module.setLEDs(0x0);
+    setTempLEDs();
   } 
 }
 
+void setTempLEDs()
+{
+  module.setLED(TM1638_COLOR_GREEN, memoryPosition-1); //turning on button led to indicate its pressed
+  if (memoryPosition==1)
+    {
+      int orginalTemp = EEPROM.read(0)*256+EEPROM.read(1); 
+      if (targetTemp>orginalTemp)
+        module.setLED(TM1638_COLOR_GREEN, 3);
+      else if (targetTemp<orginalTemp)
+        module.setLED(TM1638_COLOR_GREEN, 4);
+    }
+    else if (memoryPosition==2)
+    { 
+      int orginalTemp = EEPROM.read(2)*256+EEPROM.read(3); 
+      if (targetTemp>orginalTemp)
+        module.setLED(TM1638_COLOR_GREEN, 3);
+      else if (targetTemp<orginalTemp)
+        module.setLED(TM1638_COLOR_GREEN, 4);
+    }
+    else if (memoryPosition==3)
+    { 
+      int orginalTemp = EEPROM.read(4)*256+EEPROM.read(5); 
+      if (targetTemp>orginalTemp)
+        module.setLED(TM1638_COLOR_GREEN, 3);
+      else if (targetTemp<orginalTemp)
+        module.setLED(TM1638_COLOR_GREEN, 4);
+    }
+}
+
 void messageConstr(int count, String name1, int num1, String name2, int num2)
 {
   int i;
   }
 }
 
+