Created
February 21, 2015 23:57
-
-
Save tlorens/34995dfce7aaa9ff3bf7 to your computer and use it in GitHub Desktop.
Arduino MIcro and SSD1306 OLED Display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Metro.h> | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
#define OLED_RESET 4 | |
Adafruit_SSD1306 display(OLED_RESET); | |
#if (SSD1306_LCDHEIGHT != 64) | |
#error("Height incorrect, please fix Adafruit_SSD1306.h!"); | |
#endif | |
Metro beat = Metro(800); | |
int xCnt1 = display.width(); | |
int xCnt2 = display.width(); | |
void setup() | |
{ | |
Serial.begin(19200); | |
delay(2000); | |
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!) | |
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) | |
display.fillScreen(BLACK); | |
display.setTextWrap(false); | |
display.invertDisplay(0); | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
} | |
void loop() | |
{ | |
if (beat.check() == 1) | |
{ | |
display.dim(false); | |
beat.interval(750); | |
} | |
else | |
{ | |
beat.interval(700); | |
display.dim(true); | |
} | |
xCnt1 = scrollTextFrameXY(xCnt1, 1, 2, " Call Cyberdyne Systems + 216-232-5985 + ShockWave:Pro BBS Headquarters +++ Greetz go out to all my homies in the [2i6] "); | |
xCnt2 = scrollTextFrameXY(xCnt2, 56, 3, " .... Now we're back to the old 4Mhz days. Got some scrollers here on the old Arduino Micro!! Blinking to the beat!! Next I need to implement some bouncy text and maybe some raster bars! Anyhow, I'm getting bored with this already... Latz --iCE Breaker "); | |
display.display(); | |
} | |
int scrollTextFrameXY(int x, int y, int speed, String text) | |
{ | |
int minX = -6 * text.length(); // 6 = 6 pixels/character * text size 1 | |
display.fillRect(0, y, 128, 11, BLACK); | |
display.setTextColor(WHITE); | |
display.setCursor(x, y); | |
display.print(text); | |
x -= speed; | |
if (x < minX) | |
{ | |
x = display.width(); | |
} | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment