 
 
 
+////-------------------------------------------------------------------- Animations
+// TO DO make virtual?
+class Activity {
+  protected:
+    double currTime;          // Current time in millis, updated every call to update()
+    double lastUpdateTime;    // Last time the update ran
+    double interval;          // How many millis between updates
+  public:
+    void begin() {
+      lastUpdateTime = millis();
+    }
+
+    void update() {
+    }
+
+    boolean isTimeToUpdate() {
+      currTime = millis();
+      if (currTime - lastUpdateTime > interval) {
+        return true;
+      } else {
+        return false;
+      }
+    }
+
+    char* getName() {
+      return "Activity";
+    }
+};
+
+class NullActivity : public Activity {
+  private:
+  public:
+    void begin() {
+      debug("NulllActivity begins");
+    }
+
+    void update() {
+      debug("NulllActivity updates");
+    }
+
+    char* getName() {
+      return "NullActivity";
+    }};
+
+class BlinkActivity : public Activity {
+  private:
+    boolean isLightOn = false;
+    int interval = 2000;
+  public:
+    void begin() {
+      debug("LightActivity begins");
+    }
+
+    void update() {
+      debug("LightActivity updating?");
+      if (isTimeToUpdate()) {
+        debug("LightActivity updating");
+        if (isLightOn == true) {
+          isLightOn = false;
+          digitalWrite(LED_BUILTIN, 0);
+        } else {
+          isLightOn = true;
+          digitalWrite(LED_BUILTIN, 1);
+        }
+
+        lastUpdateTime = millis();
+      }
+    }
+
+    char* getName() {
+      return "BlinkActivity";
+    }};
+
+// The singletons for each activity
+NullActivity nullActivity;
+BlinkActivity blinkActivity;
+
+
+////-------------------------------------------------------------------- MenuSystem
+
+// This is the current activity as updated from the menus
+Activity *currentActivity;
+
+//// Rendering classes
+class MyRenderer : public MenuComponentRenderer {
+  public:
+    void render(Menu const& menu) const {
+      oled.clearDisplay();
+      oled.setCursor(0, 0);
+      Serial.print("Displaying menu");
+      Serial.println(menu.get_name());
+
+      if (menu.get_name() == "") {
+        oled.println("Main Menu");
+      } else {
+        oled.println(menu.get_name());
+      }
+
+      for (int i = 0; i < menu.get_num_components(); ++i) {
+        MenuComponent const* cp_m_comp = menu.get_menu_component(i);
+        if (cp_m_comp->is_current()) {
+          oled.print(">");
+        } else {
+          oled.print(" ");
+        }
+        cp_m_comp->render(*this);
+
+        oled.println("");
+      }
+      Serial.println("Displaying menu");
+      oled.display();
+    }
+
+    void render_menu_item(MenuItem const& menu_item) const {
+      Serial.print("Rendering menu item ");
+      Serial.println(menu_item.get_name());
+      oled.print(menu_item.get_name());
+    }
+
+    void render_back_menu_item(BackMenuItem const& menu_item) const {
+      oled.print(menu_item.get_name());
+    }
+
+    void render_numeric_menu_item(NumericMenuItem const& menu_item) const {
+      Serial.print("Rendering menu item");
+      Serial.println(menu_item.get_name());
+      oled.print(menu_item.get_name());
+    }
+
+    void render_menu(Menu const& menu) const {
+      oled.print(menu.get_name());
+    }
+};
+
+//// Menu items
+MyRenderer menuRenderer;
+MenuSystem menuSystem(menuRenderer);
+
+Menu mmSensorsMenu("Sensors");
+MenuItem sensorLight("Light", &mainMenuHandler);
+MenuItem sensorSound("Sound", &mainMenuHandler);
+
+Menu mmAnimMenu("Animations");
+MenuItem animDemo("Demo", &mainMenuHandler);
+MenuItem animLight("Flashlight", &mainMenuHandler);
+
+Menu mmSetupMenu("Setup", &mainMenuHandler);
+MenuItem setupSenseUp("CapSense Up", &mainMenuHandler);
+MenuItem setupSenseDown("CapSense Down", &mainMenuHandler);
+MenuItem setupDebugOn("Debug On", &mainMenuHandler);
+MenuItem setupDebugOff("Debug Off", &mainMenuHandler);
+
+
+//// menu selection handlers
+void mainMenuHandler(MenuComponent* p_menu_component) {
+  Serial.print("[");
+  Serial.print(p_menu_component->get_name());
+  Serial.println("] selected");
+
+  if (strcmp(p_menu_component->get_name(), "Light") == 0) {
+    Serial.println("Setting to Light");
+    currentActivity = &blinkActivity;
+    currentActivity->begin();
+  } else if (strcmp(p_menu_component->get_name(), "Sound") == 0) {
+    Serial.println("Setting to Null");
+    currentActivity = &nullActivity;
+    currentActivity->begin();
+  } else {
+    Serial.println("UNKNOWN ACTIVITY");
+  }
+
+  sprintf(messageBuffer,"nullActivity is %p  blinkActivity '%s' is %p current is %p", 
+  &nullActivity, 
+  blinkActivity.getName(), 
+  &blinkActivity, 
+  currentActivity);
+  Serial.println(messageBuffer);
+
+  Serial.print(" Blink activity is ");
+  Serial.println(blinkActivity.getName());
+
+
+  Serial.print(" Current activity is ");
+  Serial.println(currentActivity->getName());
+
+}
+
+
 ////-------------------------------------------------------------------- Main
 void setup() {
 

    }
  */

  digitalWrite(LED_BUILTIN, 1);
  delay(200);
  digitalWrite(LED_BUILTIN, 0);
}


}

void loop() {
  //Serial.println("Top of loop");
  if (CircuitPlayground.rightButton()) {
    debug("Right");
  }
