// --------------------------- INCLUDE LIB --------------------------- //
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//#include <TaskScheduler.h> //non utilizzato per il momento
// --------------------------- ADAFRUIT DEFINE --------------------------- //
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// --------------------------- --------------------------- //
const int LedPin = 13; // Internal LED connected to digital pin 13
int LedVal = 0;
const int ButtonPin = 9; // pushbutton connected to digital pin x
int ButtonVal = 0; // variable to store the read value
const int PotPin = A1; // pushbutton connected to digital pin 7
int PotVal = 0; // variable to store the read value
int PotValPerc = 0; // variable to store the read value
int PotValPercLog = 0;
const int ButtonPagePin = 2; // pushbutton connected to digital pin x
int8_t ButtonPageVal = 0; // variable to store the read value
int8_t ButtonPageVal_old = 0;
int8_t ButtonPageVal_Deb1 = 0;
int8_t ButtonPageVal_Deb1_old = 0;
int8_t ButtonPageVal_Deb2 = 0;
int8_t ButtonPageVal_Deb2_old = 0;
int ButtonPage_DebDelay1 = 400; // the debounce time; increase if the output flickers
int ButtonPage_DebDelay2 = 30; // the debounce time; increase if the output flickers
int PageNumb1 = 0; // Page per pressione lunga
int PageNumb2 = 0; // Page per pressione corta
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long _t10msL = 0; // Last x cycles call
unsigned long _t250msL = 0; // Last x cycles call
const int DispUpdateFreq = 15; // Frequenza aggiornamento display [ms] (15ms = 66Hz)
const int LogSize = 30;
const int LogScale = 4; // Fare in modo da avere LogSize*LogScale = 100 circa. (Numero pixel su asse x)
const int LogTInterval = 5000; //Tempo totale del log [ms]
int LogCycleTime = LogTInterval/(LogSize); // Calcolo Tempo di campionamento in modo da avere il LogTInterval desiderato
int8_t LogValue[(LogSize)] = { 0 };
int LogValue_a = 0; // indice a per ciclo for
int LogValue_t = 0;
// Altezza log 50 pixel
const int LogXpos = 5; // Posizione orizzontale per inizio del Log. Il log si svilupperà poi per xx pixel verso il destra
const int LogYpos = 58; // Posizione verticale per inizio del Log. Il log si svilupperà poi per 50 pixel verso l'alto. (0 indica l'angolo in alto a sx del display)
// --------------------------- LOGO BABY YODA --------------------------- //
const unsigned char BabyYoda_logo[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0x00, 0x07, 0xc1, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x8f, 0xf0, 0x1c, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x80, 0x7f, 0x70, 0x00, 0x06, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc2, 0x07, 0xe0, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x60, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x30, 0x1c, 0x00, 0x49, 0x00, 0x00, 0x70, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x06, 0x00, 0x08, 0x00, 0x0f, 0x81, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x03, 0x01, 0x00, 0x7c, 0x30, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x01, 0x3f, 0x00, 0x7e, 0x60, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x01, 0x7f, 0x80, 0xfe, 0x40, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x01, 0x3f, 0x89, 0xfe, 0x40, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x00, 0x3f, 0x91, 0xfe, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xc0, 0x1f, 0x81, 0xf8, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x81, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x00, 0x00, 0x01, 0x9f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xc0, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x3f, 0xff, 0xf0, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x1e, 0xe0, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0, 0x00, 0x07, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xe0, 0x00, 0x1d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x98, 0x00, 0xcd, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x8f, 0x81, 0x99, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x4b, 0x9f, 0x19, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x72, 0x68, 0x2c, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x92, 0x48, 0x4c, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xd0, 0x48, 0xdf, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x7c, 0x09, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xf8, 0x0b, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x60, 0x88, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x88, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x88, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x70, 0x88, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x60, 0x88, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x60, 0x88, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x78, 0xc8, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// --------------------------- LOGO ARDUINO --------------------------- //
// 'arduino logo', 127x63px
const unsigned char arduino_logo[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0x07, 0xff, 0xff, 0xe1, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0xff, 0xfe, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x3f, 0xf8, 0x00, 0x0f, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x1f, 0xf0, 0x00, 0x03, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x0f, 0xe0, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0xf8, 0x03, 0xc0, 0x3f, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x07, 0xff, 0x03, 0x80, 0xff, 0xc0, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x0f, 0xff, 0x81, 0x03, 0xff, 0xe0, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xff, 0xc0, 0x07, 0xff, 0xf0, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xff, 0xe0, 0x0f, 0xe3, 0xf0, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xff, 0xe0, 0x0f, 0xe3, 0xf8, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x3c, 0x01, 0xf0, 0x1f, 0x80, 0xf8, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x3c, 0x01, 0xf0, 0x1f, 0x00, 0xf8, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x3e, 0x03, 0xf0, 0x1f, 0x81, 0xf8, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, 0xff, 0xf0, 0x0f, 0xe3, 0xf8, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xff, 0xe0, 0x0f, 0xe7, 0xf0, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0xff, 0xc0, 0x07, 0xff, 0xf0, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x0f, 0xff, 0x80, 0x03, 0xff, 0xe0, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x07, 0xff, 0x01, 0x81, 0xff, 0xc0, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x03, 0xfe, 0x03, 0x80, 0xff, 0x80, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x0f, 0xe0, 0x00, 0x03, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x1f, 0xf0, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0x7f, 0xfc, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x01, 0xff, 0xff, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
unsigned long start = millis();
// --------------------------- DISPLAY INITIALIZATION --------------------------- //
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
// Display the splash screen (we're legally required to do so)
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(1500); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// --------------------------- Arduino Logo --------------------------- //
display.drawBitmap(0, 0, arduino_logo, 127, 63, WHITE);
display.display();
delay(1500);
display.clearDisplay();
// --------------------------- Baby Yoda Logo --------------------------- //
display.drawBitmap(0, 0, BabyYoda_logo, 128, 64, WHITE);
display.display();
delay(300);
display.startscrollright(0x00, 0x0F);
delay(1000);
display.stopscroll();
delay(1000);
display.clearDisplay();
display.drawBitmap(28, 0, BabyYoda_logo, 128, 64, WHITE);
display.setTextSize(0);
display.setTextColor(WHITE);
display.setCursor(1, 55);
display.print("May the 4th be with u");
display.display();
delay(3000);
display.clearDisplay();
// --------------------------- PIN INITIALIZATION --------------------------- //
pinMode(LedPin, OUTPUT); // sets the digital pin 13 as output
pinMode(ButtonPin, INPUT_PULLUP); // sets the digital pin 7 as input
pinMode(ButtonPagePin, INPUT_PULLUP); // sets the digital pin 7 as input
pinMode(PotPin, INPUT);
}
void loop() {
LedVal = digitalRead(LedPin); // read the input pin
ButtonVal = digitalRead(ButtonPin); // read the input pin
ButtonPageVal = digitalRead(ButtonPagePin); // read the input pin
PotVal = analogRead(PotPin); // read the input pin
PotValPerc = map(PotVal, 0, 1023, 0, 100);
PotValPercLog = map(PotVal, 0, 1023, 0, 50);
//String Stringa1 = "Pot Value: " + String(PotVal);
//String Stringa2 = "Button Value: " + String(ButtonVal);
//String Stringa1n = "Pot Value: " + String(PotValPerc);
//String Stringa3 = "ButtonPage Value: " + String(ButtonPageVal);
//Serial.println(Stringa1 + " " + Stringa2 + " " + Stringa3);
if (ButtonVal == LOW || PotVal >= 500) {
digitalWrite(LedPin, 1); // sets the LED to the button's value
} else {
digitalWrite(LedPin, 0); // sets the LED to the button's value
}
// --------------------------- DEBOUNCE --------------------------- //
// DEBOUNCE solo in attivazione e disattivazione oppure solo in attivazione con disattivazione immediata
// If the switch changed, due to noise or pressing:
// DEBOUNCE PER BUTTON PAGE 1 (con debounce lungo)
// - Debouncing usato in attivazione e disattivazione
//if (ButtonPageVal != ButtonPageVal_old) {
if (ButtonPageVal == 0 && ButtonPageVal_old == 1) { // Debouncing usato solo in attivazione
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > ButtonPage_DebDelay1) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (ButtonPageVal != ButtonPageVal_Deb1) {
ButtonPageVal_Deb1 = ButtonPageVal;
}
}
// DEBOUNCE PER BUTTON PAGE 2 (con debounce breve)
//if (ButtonPageVal != ButtonPageVal_old) { // Debouncing usato in attivazione e disattivazione
if (ButtonPageVal == 0 && ButtonPageVal_old == 1) { // Debouncing usato solo in attivazione
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > ButtonPage_DebDelay2) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (ButtonPageVal != ButtonPageVal_Deb2) {
ButtonPageVal_Deb2 = ButtonPageVal;
}
}
ButtonPageVal_old = ButtonPageVal;
// --------------------------- CONTATORE PAGINA --------------------------- //
if (ButtonPageVal_Deb1 == 0 && ButtonPageVal_Deb1_old == 1) {
PageNumb1 = PageNumb1 + 1;
if (PageNumb1 >= 2) {
PageNumb1 = 0;
}
}
//if (ButtonPageVal_Deb2 == 0 && ButtonPageVal_Deb2_old == 1){ // Calcolo pagina classico sul secondo debounce
if (ButtonPageVal_Deb2 == 1 && ButtonPageVal_Deb2_old == 0 && ButtonPageVal_Deb1_old == 1) { // Faccio scattare la pagina 2 solo se ho rilasciato il tasto prima del debounce della pagina 1
PageNumb2 = PageNumb2 + 1;
if (PageNumb2 >= 3) {
PageNumb2 = 0;
}
}
// Aggiorno Variabili _old
ButtonPageVal_Deb1_old = ButtonPageVal_Deb1;
ButtonPageVal_Deb2_old = ButtonPageVal_Deb2;
//Serial.println(String(ButtonPageVal_Deb1) + " " + String(ButtonPageVal_Deb2) + " " + String(PageNumb1) + " " + String(PageNumb2));
// --------------------------- DEFINIZIONE PAGINE --------------------------- //
// --------------------------- PAGINA 1
if (PageNumb2 == 0) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
// Display static text
display.setCursor(10, 5);
display.print("Pot Value: " + String(PotValPerc));
display.setCursor(95, 5);
display.print("[Prc]");
display.drawLine(0, 15, 127, 15, WHITE);
display.setCursor(10, 20);
display.print("Button Value: " + String(ButtonVal));
display.setCursor(10, 32);
display.print("ButtonPage Value: " + String(ButtonPageVal));
// Barra variabile
display.drawLine(110, 48, 110, 52, WHITE);
display.drawLine(10, 48, 10, 52, WHITE);
display.drawLine(60, 48, 60, 52, WHITE);
display.drawLine(10, 49, 10 + PotValPerc, 49, WHITE);
display.drawLine(10, 50, 10 + PotValPerc, 50, WHITE);
display.drawLine(10, 51, 10 + PotValPerc, 51, WHITE);
// Rettangolo contorno schermo
display.drawRect(0, 0, 128, 64, WHITE);
}
// --------------------------- PAGINA 2
if (PageNumb2 == 1) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
// Display static text
display.setCursor(10, 5);
display.print("LedState:");
display.setCursor(62, 30);
display.print(String(LedVal));
display.drawRect(0, 0, 128, 64, WHITE);
}
// --------------------------- PAGINA 3
if (PageNumb2 == 2) {
// --------------------------- PAGINA 3.0
if (PageNumb1 == 0) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(2, 0);
display.print("100");
display.setCursor(100, 0);
display.print(String(PotValPerc) + "%");
display.setCursor(100, 10);
display.print("Led" + String(LedVal));
for (int LogValue_t = 0; LogValue_t <= LogSize - 2; LogValue_t++) {
// - Stampo solo il pixel i
//display.drawPixel((LogValue_t * LogScale) + LogXpos, -(LogValue[LogValue_t]) + LogYpos, WHITE);
// - Interpolazione lineare del plot. Tempo scalato x3. Sostituire tutti LogScale della formula per riscalare
display.drawLine((LogValue_t * LogScale) + LogXpos, -(LogValue[LogValue_t]) + LogYpos, (LogValue_t * LogScale) + LogScale + LogXpos, -(LogValue[LogValue_t + 1]) + LogYpos, WHITE);
}
// Assi
display.drawLine(0, 0, 0, 63, WHITE); // Asse y
// display.drawLine(0, 63, 127, 63, WHITE); // Asse x
// Linee riferimento assi
display.drawLine(0, LogYpos, 3, LogYpos, WHITE);
display.drawLine(0, LogYpos - 50, 3, LogYpos - 50, WHITE);
// Linee tratteggiate Assi
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos - 13 - 12 - 12 - 13, WHITE); // Tratteggio 100%
}
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos - 13 - 12 - 12, WHITE); // Tratteggio 75%
}
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos - 13 - 12, WHITE); // Tratteggio 50%
}
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos - 13, WHITE); // Tratteggio 25%
}
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos, WHITE); // Tratteggio 0%
}
}
// --------------------------- PAGINA 3.1
if (PageNumb1 == 1) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(3, 0);
display.print("50");
display.setCursor(100, 0);
display.print(String(PotValPerc) + "%");
display.setCursor(100, 10);
display.print("Led" + String(LedVal));
for (int LogValue_t = 0; LogValue_t <= LogSize - 2; LogValue_t++) {
// - Stampo solo il pixel i
//display.drawPixel((LogValue_t * LogScale) + LogXpos, -(LogValue[LogValue_t]) + LogYpos, WHITE);
// - Interpolazione lineare del plot. Tempo scalato x3. Sostituire tutti LogScale della formula per riscalare
display.drawLine((LogValue_t * LogScale) + LogXpos, -(LogValue[LogValue_t] * 2) + LogYpos, (LogValue_t * LogScale) + LogScale + LogXpos, -(LogValue[LogValue_t + 1] * 2) + LogYpos, WHITE);
}
// Assi
display.drawLine(0, 0, 0, 63, WHITE); // Asse y
// display.drawLine(0, 63, 127, 63, WHITE); // Asse x
// Linee riferimento assi
display.drawLine(0, LogYpos, 3, LogYpos, WHITE);
display.drawLine(0, LogYpos - 50, 3, LogYpos - 50, WHITE);
// Linee tratteggiate Assi
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos - 13 - 12 - 12 - 13, WHITE); // Tratteggio 100%
}
//for (int i = 0; i <= 128; i=i+4) {
// display.drawPixel(i, LogYpos-13-12-12, WHITE); // Tratteggio 75%
//}
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos - 13 - 12, WHITE); // Tratteggio 50%
}
//for (int i = 0; i <= 128; i=i+4) {
// display.drawPixel(i, LogYpos-13, WHITE); // Tratteggio 25%
//}
for (int i = 0; i <= 128; i = i + 4) {
display.drawPixel(i, LogYpos, WHITE); // Tratteggio 0%
}
}
}
// --------------------------- AGGIORNO VARIABILE LOG --------------------------- //
// 250ms System calls
// Creo il vettore con gli elementi del Log:
// - LogValue[0] è la più vecchia, LogValue [finale] del vettore la più recente
// In questo modo a desta abbiamo il valore più recente
/*if (millis() - _t250msL >= LogCycleTime) {
if (LogValue_a > (LogSize - 1)) {
LogValue_a = 0;
}
for (int i = 0; i <= (LogSize - 2); i++) {
LogValue[i] = LogValue[i + 1];
}
LogValue[(LogSize - 1)] = PotValPercLog;
//Serial.println( String(LogValue_a) );
//Serial.println( String(LogValue[LogValue_a]) );
LogValue_a = LogValue_a + 1;
_t250msL = millis();
}
*/
// - LogValue[0] è la più recente, LogValue [finale] del vettore la più vecchia
// In questo modo a sinistra abbiamo il valore più recente
if (millis() - _t250msL >= LogCycleTime) {
if (LogValue_a > (LogSize - 1)) {
LogValue_a = 0;
}
for (int i = 0; i <= (LogSize - 2); i++) {
LogValue[(LogSize - 1) - i] = LogValue[(LogSize - 1) - i - 1];
}
LogValue[0] = PotValPercLog;
//Serial.println( String(LogValue_a) );
//Serial.println( String(LogValue[LogValue_a]) );
LogValue_a = LogValue_a + 1;
_t250msL = millis();
}
// --------------------------- AGGIORNO DISPLAY --------------------------- //
// 10ms System calls
if (millis() - _t10msL >= DispUpdateFreq) {
DispUpdate();
_t10msL = millis();
}
}
// ------- FUNCTION ------- //
void DispUpdate() {
display.display();
}