#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 64;
const int SCREEN_ADDRESS =0x3C;
Adafruit_SSD1306 display( SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
// pin numbers
const int selectButtonPin = 2;
const int moveButtonPin = 4;
// const int ledPin = 11;
// variables will change:
int selectButtonState = 0; // variable for reading the selecting pushbutton status
int moveButtonState = 0; // variable for reading the moving pushbutton status
int selectTimesPressed = 0; // variable for detecting if user is on different screen
int moveTimesPressed = 0; // variable for detecting if user is on different screen
int lastSelectButtonState = LOW; // variable for pulsing
int lastMoveButtonState = LOW; // variable for pulsing
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
// put your setup code here, to run once:
display.begin( SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.clearDisplay();
display.display();
pinMode(selectButtonPin, INPUT_PULLUP);
pinMode(moveButtonPin, INPUT_PULLUP);
}
void loop() {
display.fillRect(0,0,128,64,SSD1306_BLACK);
display.setCursor(5,10);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.println("RTC Stuff");
// delay(1000);
selectButtonState = digitalRead(selectButtonPin);
moveButtonState = digitalRead(moveButtonPin);
// compare the buttonState to its previous state
if (selectButtonState != lastSelectButtonState) {
// if the state has changed, increment the counter
if (selectButtonState == LOW) {
// if the current state is HIGH then the button went from off to on:
selectTimesPressed++;
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastSelectButtonState = selectButtonState;
// check if the pushbutton is pressed. If it is, the selectButtonState is LOW:
if (selectTimesPressed % 2 == 1) {
/****************/
/* DISPLAY MENU */
/****************/
// Select Box
if (moveTimesPressed % 2 == 0) {
display.fillRect(0,32,128,64,SSD1306_BLACK); // erase previous box
display.fillRect(0,0,128,32,SSD1306_WHITE);
display.fillRect(2,2,124,28,SSD1306_BLACK);
} else {
display.fillRect(0,0,128,32,SSD1306_BLACK); // erase previous box
display.fillRect(0,32,128,64,SSD1306_WHITE);
display.fillRect(2,34,124,60,SSD1306_BLACK);
}
// Staring Pomo Timer
display.setCursor(5,10);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.println("Start Pomo");
// Set Pomo Timer
display.setCursor(5,42);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.println("Set Pomo");
}
display.display();
}