| 
						
						
						
					 | 
				
				 | 
				
					@ -1,16 +1,15 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define MAX_OPTIONS 10      //Maximum number of options for each menu
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define MAX_MENUS 3
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define MAX_GRAPH 3
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define __DEBUG__
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include <Arduino.h>
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include <SPI.h>
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include <Wire.h>
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include <Adafruit_GFX.h>
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#include <Adafruit_SSD1306.h>
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define __DEBUG__
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define DISP_WIDTH 128 // OLED display width
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define DISP_HEIGHT 64 // OLED display height
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define MAX_OPTIONS 10      //Maximum number of options for each menu
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define MAX_MENUS 3
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define MAX_GRAPH 3
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define DISP_WIDTH 128      // OLED display width
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define DISP_HEIGHT 64      // OLED display height
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#define REFRESH 10          //Refresh time in ms
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Adafruit_SSD1306 display(DISP_WIDTH, DISP_HEIGHT, &Wire, -1); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					int i = 0; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -83,7 +82,7 @@ class Menu{    //ContentTypeMenu true, it is a menu | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  int optPPage; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  int previousScreen = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  int previousContentType = true; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  int previousContentType = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					   | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  public: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -116,6 +115,14 @@ class Menu{    //ContentTypeMenu true, it is a menu | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    display.display(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					   | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  int extractPos(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    return(this->pos); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  int extractOptNumber(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    return(this->options); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void increasePos(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->pos++; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -481,11 +488,13 @@ class Screen{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void increasePos(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->menu[this->currentScreen].increasePos(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(this->menu[this->currentScreen].extractPos() < this->menu[this->currentScreen].extractOptNumber() - 1) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      this->menu[this->currentScreen].increasePos(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void decreasePos(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->menu[this->currentScreen].decreasePos(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(this->menu[this->currentScreen].extractPos() > 0) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      this->menu[this->currentScreen].decreasePos(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					   | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void goTo(){ | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -525,19 +534,120 @@ class Screen{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void plusAction(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(contentType == 0){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      increasePos(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void minusAction(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(contentType == 0){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      decreasePos(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					   | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					}; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					class Keyboard{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  private: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  byte goTo; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  byte goBack; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  byte plus; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  byte minus; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  byte debounceTime; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  Screen * screen; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  public: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  Keyboard(byte goTo, byte goBack, byte plus, byte minus, byte debounceTime, Screen * screen){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->goTo = goTo; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->goBack = goBack; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->plus = plus; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->minus = minus; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->debounceTime = debounceTime; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->screen = screen; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    pinMode(goTo, INPUT_PULLUP); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    pinMode(goBack, INPUT_PULLUP); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    pinMode(plus, INPUT_PULLUP); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    pinMode(minus, INPUT_PULLUP); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void checkGoTo(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    static char cont; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(digitalRead(this->goTo) == LOW) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont++; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(cont == debounceTime/REFRESH){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      this->screen->goTo(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      while(digitalRead(this->goTo) == LOW){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					   | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void checkGoBack(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    static char cont; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(digitalRead(this->goBack) == LOW){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont++; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      Serial.println("Ayudaaaaa"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(cont == debounceTime/REFRESH){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      this->screen->goBack(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      Serial.println("Ayudaaaaant"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      while(digitalRead(this->goBack) == LOW){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void checkPlus(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    static char cont; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(digitalRead(this->plus) == LOW) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont++; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(cont == debounceTime/REFRESH){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      this->screen->plusAction(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      while(digitalRead(this->plus) == LOW){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void checkMinus(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    static char cont; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(digitalRead(this->minus) == LOW) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont++; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    if(cont == debounceTime/REFRESH){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      cont = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      this->screen->minusAction(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      while(digitalRead(this->minus) == LOW){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  void control(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->checkGoTo(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->checkGoBack(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->checkPlus(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    this->checkMinus(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					}; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Screen screen; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Screen screen, * disp = &screen; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					Keyboard keyboard(14, 4, 12, 13, 40, disp); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void setup(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  screen.configure(true); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  Serial.println("Screen created"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					   | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  screen.createMenu(128, 13);             //Menu 0
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  screen.createMenu(128, 13);             //Menu 1
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -571,7 +681,7 @@ void setup(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					void loop(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  screen.control();            //Controls the screen and redraws if needed
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  delay(10); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  keyboard.control(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  if(i <= 100){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    screen.graphAssignValue(1, i);    //Assigning a demo value to Graph 1
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -580,4 +690,6 @@ void loop(){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  else | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    i = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  delay(REFRESH);                   //Refresh time (approx)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} |