#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define BUTTON_PIN A0
#define POTI_PIN A1
const unsigned char ground [] PROGMEM = {
0xbb, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xee, 0xee, 0x77, 0x77, 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd,
0xbb, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xee, 0xee, 0x77, 0x77, 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd
};
void drawSector(int x, int y, char* type){
if(type == "g"){
display.drawBitmap(x, y, ground, 16, 16, WHITE);
}
}
void drawRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
char* mySectors[16] = {"g","g","g","g",
"g","g","g","g",
"n","n","n","n",
"n","n","n","n"};
char* myMenue[8] ={};
void buildSectors(){
display.clearDisplay();
int row = 0;
int col = 0;
for (byte i = 0; i < 16; i = i + 1) {
drawSector((col*16), (row*16), mySectors[i]);
if(col < 3){col++;}else{col = 0;row++;}
}
display.display();
}
void setCursor(int x, int y){
display.drawRect((x*16)+1, (y*16)+1, 15, 15,0xffff);
display.drawRect((x*16)+1, (y*16)+1, 14, 14,0x0000);
display.display();
}
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(POTI_PIN, INPUT);
Serial.println(F("Starting!"));
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
Serial.println(F("Initialized!"));
buildSectors();
setCursor(0,0);
}
int pressed = false;
int counter = 0;
int lastVal = 123;
void loop() {
if (digitalRead(BUTTON_PIN) == LOW && pressed != true) {
counter++;
pressed = true;
}
if (digitalRead(BUTTON_PIN) == HIGH && pressed == true) {
delay(700);
pressed = false;
}
int value = analogRead(A1);
int val = map(value, 0, 1023, 0, 16);
if (analogRead(A1) != value){
if(val != lastVal){
buildSectors();
if(val == 0){setCursor(0,0);}
if(val == 1){setCursor(1,0);}
if(val == 2){setCursor(2,0);}
if(val == 3){setCursor(3,0);}
if(val == 4){setCursor(0,1);}
if(val == 5){setCursor(1,1);}
if(val == 6){setCursor(2,1);}
if(val == 7){setCursor(3,1);}
if(val == 8){setCursor(0,2);}
if(val == 9){setCursor(1,2);}
if(val == 10){setCursor(2,2);}
if(val == 11){setCursor(3,2);}
lastVal = val;
}
}
}