#include <SPI.h>
#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
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMAMOGUS 10 // Number of amogus in the animation example
#define AMOGUS_HEIGHT 16
#define AMOGUS_WIDTH 16
static const unsigned char PROGMEM amogus_bmp[] =
{ B00011111, B11100000,
B00100000, B00010000,
B01000000, B00001000,
B01111111, B00001000,
B10010000, B10001000,
B10110000, B10001110,
B10000000, B10001001,
B01111111, B00001001,
B01000000, B00001001,
B01000000, B00001001,
B01001111, B10001110,
B01000100, B10001000,
B01000100, B10001000,
B01000100, B10001000,
B00111100, B01110000,
B00000000, B00000000 };
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Showcase
testanimate(amogus_bmp, AMOGUS_WIDTH, AMOGUS_HEIGHT); // Animate amogus bitmaps
}
void loop() {
}
#define XPOS 0 // Indexes into the 'icons' array in function below
#define YPOS 1
#define DELTAY 2
void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) {
int8_t f, icons[NUMAMOGUS][3];
// Initialize 'amogus' positions
for(f=0; f< NUMAMOGUS; f++) {
icons[f][XPOS] = random(1 - AMOGUS_WIDTH, display.width());
icons[f][YPOS] = -AMOGUS_HEIGHT;
icons[f][DELTAY] = random(1, 6);
Serial.print(F("x: "));
Serial.print(icons[f][XPOS], DEC);
Serial.print(F(" y: "));
Serial.print(icons[f][YPOS], DEC);
Serial.print(F(" dy: "));
Serial.println(icons[f][DELTAY], DEC);
}
for(;;) { // Loop forever...
display.clearDisplay(); // Clear the display buffer
// Draw each amogus:
for(f=0; f< NUMAMOGUS; f++) {
display.drawCircle(icons[f][XPOS], icons[f][YPOS], h/2, SSD1306_WHITE);
}
display.display(); // Show the display buffer on the screen
delay(200); // Pause for 1/10 second
// Then update coordinates of each amogus...
for(f=0; f< NUMAMOGUS; f++) {
icons[f][YPOS] += icons[f][DELTAY];
// If amogus is off the bottom of the screen...
if (icons[f][YPOS] >= display.height()) {
// Reinitialize to a random position, just off the top
icons[f][XPOS] = random(1 - AMOGUS_WIDTH, display.width());
icons[f][YPOS] = -AMOGUS_HEIGHT;
icons[f][DELTAY] = random(1, 6);
}
}
}
}