Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Adafruit_SSD1306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,29 @@ static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {

#define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; }

uint16_t Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
return BLACK;

// check rotation, move pixel around if necessary
switch (getRotation()) {
case 1:
ssd1306_swap(x, y);
x = WIDTH - x - 1;
break;
case 2:
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
break;
case 3:
ssd1306_swap(x, y);
y = HEIGHT - y - 1;
break;
}

return (buffer[x+ (y/8)*SSD1306_LCDWIDTH] & (1 << (y&7)))? WHITE: BLACK;
}

// the most basic function, set a single pixel
void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
Expand Down
7 changes: 4 additions & 3 deletions Adafruit_SSD1306.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ All text above, and the splash screen must be included in any redistribution
SSD1306_96_16

-----------------------------------------------------------------------*/
// #define SSD1306_128_64
#define SSD1306_128_32
#define SSD1306_128_64
// #define SSD1306_128_32
// #define SSD1306_96_16
/*=========================================================================*/

Expand Down Expand Up @@ -159,7 +159,8 @@ class Adafruit_SSD1306 : public Adafruit_GFX {

void dim(boolean dim);

void drawPixel(int16_t x, int16_t y, uint16_t color);
uint16_t getPixel(int16_t x, int16_t y);
void drawPixel(int16_t x, int16_t y, uint16_t color);

virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers

Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98

This example is for a 128x64 size display using SPI to communicate
4 or 5 pins are required to interface

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// If using software SPI (the default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

/* Uncomment this block to use hardware SPI
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
*/

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

int ii = 0;

void setup() {
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
// init done

// Setup text parameters
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextScroll(true);

// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(1000);

// Clear the buffer.
display.clearDisplay();
}


void loop() {
display.print("Message #");
display.println(ii++);
display.display();
delay(1000);
}