diff --git a/Adafruit_SSD1306.cpp b/Adafruit_SSD1306.cpp index e9726563..e37cf21c 100644 --- a/Adafruit_SSD1306.cpp +++ b/Adafruit_SSD1306.cpp @@ -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())) diff --git a/Adafruit_SSD1306.h b/Adafruit_SSD1306.h index 983f2775..39cf2930 100644 --- a/Adafruit_SSD1306.h +++ b/Adafruit_SSD1306.h @@ -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 /*=========================================================================*/ @@ -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); diff --git a/examples/ssd1306_128x64_spi_text_scroll/ssd1306_128x64_spi_text_scroll.ino b/examples/ssd1306_128x64_spi_text_scroll/ssd1306_128x64_spi_text_scroll.ino new file mode 100644 index 00000000..687dd3e9 --- /dev/null +++ b/examples/ssd1306_128x64_spi_text_scroll/ssd1306_128x64_spi_text_scroll.ino @@ -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 +#include +#include +#include + +// 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); +} +