#include <arduino-timer.h>
#include <EEPROM.h>
int eeAddress = 1;
bool bulb = 0;
Timer<2, millis, const char *> Read_timer;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Read_timer.every(100, TimerRead);
pinMode(2, INPUT_PULLUP); // set pin 2 input - Filter tank low
}
void loop() {
// put your main code here, to run repeatedly:
Read_timer.tick();
}
void TimerRead(){
// this code toggles the bulb without any globals
// you need a global 4 other routines to query bulb though
static bool Flag_2 = 0;
static bool Flag_1 = 0;
bool state = ReadDigitalButton(2);
if (state == 1){ // Rung 1 if button closed
Flag_2 = 1; // compare
Flag_1 = 0;
}
else{
Flag_2 = 0;
Flag_1 = 1;
}
if (Flag_1 == 1 || bulb == 1){ // Rung 2
if (Flag_2 == 0){
bulb = 1;
}
else {
bulb = 0;
}
}
Serial.print("Buttton " );Serial.println(state);
Serial.print("Bulb " );Serial.println(bulb);
return true;
}
bool ReadDigitalButton(int dport){
bool foo = !digitalRead(dport); //
//if (foo == true){
// Serial.print("FOO @ port " );Serial.print(dport);Serial.print(" Output: ");Serial.println(foo);
//}
return foo;
}