#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define BARS 8
#define BAR_WIDTH 16
uint16_t drawRGB24toRGB565(uint8_t r, uint8_t g, uint8_t b) {
return ((r / 8) << 11) | ((g / 4) << 5) | (b / 8);
}
uint16_t colors[] = {
drawRGB24toRGB565(0xFF, 0, 0),
drawRGB24toRGB565(0, 0xFF, 0),
drawRGB24toRGB565(0, 0, 0xFF),
drawRGB24toRGB565(0xFF, 0xFF, 0),
drawRGB24toRGB565(0xFF, 0, 0xFF),
drawRGB24toRGB565(0, 0xFF, 0xFF),
drawRGB24toRGB565(0, 0, 0),
drawRGB24toRGB565(0xFF, 0xFF, 0xFF)
};
void setup() {
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
for (int b = 0; b < BARS; ++b) {
display.fillRect(0+(b*BAR_WIDTH), 0, BAR_WIDTH, display.height(), colors[b]);
}
display.display();
delay(2000);
}
void loop() {
int sample = analogRead(A0);
Serial.println(sample);
}