#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// SETUP OLED SCREEN
const byte SCREEN_WIDTH = 128; // OLED display width, in pixels
const byte SCREEN_HEIGHT = 64; // OLED display height, in pixels
const int OLED_RESET = -1; // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Used to rotate bitmap
#define DEG2RAD 0.0174532925
int angle = 0;
// Battery Icon
const static uint8_t PROGMEM batteryH [] =
{ 16, 8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0xff, 0xc0, 0xff, 0xc0, 0xff, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
// Battery Icon
const static uint8_t PROGMEM batteryV [] =
{ 8, 16,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
void setup() {
// Need to hardware reset my display manually via pin 7
digitalWrite(7, LOW);
pinMode(7, OUTPUT);
delay(200);
pinMode(7, INPUT);
delay(5);
// by default, we'll generate the high voltage from the 3.3v line
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize
}
void loop() {
display.clearDisplay(); // Clear the display buffer
display.setTextSize(1);
display.setTextColor(WHITE);
// drawRotatedBitmap(1, 0, batteryH, 270);
display.drawBitmap(0, 0, batteryV, 4, 8, 1);
display.setCursor(10,0);
display.println("34%");
display.display();
delay(100); // Pause so we see it
}
void drawRotatedBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint16_t angle) {
// example of use:
// drawRotatedBitmap(1, 0, batteryH, 270);
uint8_t w = pgm_read_byte(bitmap++);
uint8_t h = pgm_read_byte(bitmap++);
int16_t newx, newy;
uint8_t data = 0;
float cosa = cos(angle * DEG2RAD), sina = sin(angle * DEG2RAD);
x = x - ((w * cosa / 2) - (h * sina / 2));
y = y - ((h * cosa / 2) + (w * sina / 2));
for (int16_t j = 0; j < h; j++) {
for (int16_t i = 0; i < w; i++ ) {
if ((j * w + i) & 7) data <<= 1;
else data = pgm_read_byte(bitmap++);
newx = 0.5 + x + ((i * cosa) - (j * sina));
newy = 0.5 + y + ((j * cosa) + (i * sina));
if (data & 0x80) display.drawPixel(newx, newy, 1);
//else display.drawPixel(newx, newy, 0);
}
}
}