   // put your setup code here, to run once:
   // initialize the digital pin as an output.
   pinMode(1, OUTPUT); //LED on Model A   
-  pinMode(6, INPUT);//Button pin
+  attachInterrupt(digitalPinToInterrupt(PULSE_PIN), trigger_pulse, FALLING);
+  pinMode(DEBUG_LED, OUTPUT);//Debugging LED
+  attachInterrupt(digitalPinToInterrupt(BTN_1), toggle_b1, FALLING);
+  attachInterrupt(digitalPinToInterrupt(BTN_2), toggle_b2, FALLING);
+  attachInterrupt(digitalPinToInterrupt(BTN_3), toggle_b3, FALLING);
+  attachInterrupt(digitalPinToInterrupt(BTN_4), toggle_b4, FALLING);
 }
 
 bool btn_state = false;
 
 void loop() {
   int remainingTimeBudget = ui.update();
+  yield();
+  long deadline = millis() + remainingTimeBudget;
   if (remainingTimeBudget > 0) {
-    // You can do some work here
-    // Don't do stuff if you are below your
-    // time budget.
-    bool curr_btn_state = (digitalRead(6) == LOW) ? false : true;
-    if(curr_btn_state != btn_state) {
-      if(curr_btn_state == false) {//PULSE FINISHED
+    
+    if(b1_pressed == true) {
+      ui.nextFrame();
+      b1_pressed = false;
+    }
+    
+    if(b2_pressed == true) {
+      ui.previousFrame();
+      b2_pressed = false;
+    }
+    
+    if(b3_pressed == true) {
+      //handle b3
+      b3_pressed = false;
+    }
+    
+    if(b4_pressed = true) {
+      //handle b4
+      b4_pressed = false;
+    }
+    
+    if(pulse_triggered == true) {
         pulse_count_current_kwh++;
         if(pulse_count_current_kwh == PULSES_PER_KWH) {
           consumption_total++;


bool isConnected = false;

void setup() {
  ui.setTargetFPS(30);
  ui.setActiveSymbole(activeSymbole);


#define PULSES_PER_KWH 375
#define WH_PER_PULSE (1000.0F / PULSES_PER_KWH)

#define BTN_1 9
#define BTN_2 8
#define BTN_3 7
#define BTN_4 6
#define PULSE_PIN 5
#define DEBUG_LED 10

int pulse_count_current_kwh;

