Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added HW scrolling support

commit c389c85cfd935f3beb90917f5d589950939c064d 1 parent aac9ccf
K.Townsend authored
View
68 Adafruit_SSD1306.cpp
@@ -301,6 +301,74 @@ void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
}
}
+// startscrollright
+// Activate a right handed scroll for rows start through stop
+// Hint, the display is 16 rows tall. To scroll the whole display, run:
+// display.scrollright(0x00, 0x0F)
+void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop){
+ ssd1306_command(SSD1306_RIGHT_HORIZONTAL_SCROLL);
+ ssd1306_command(0X00);
+ ssd1306_command(start);
+ ssd1306_command(0X00);
+ ssd1306_command(stop);
+ ssd1306_command(0X01);
+ ssd1306_command(0XFF);
+ ssd1306_command(SSD1306_ACTIVATE_SCROLL);
+}
+
+// startscrollleft
+// Activate a right handed scroll for rows start through stop
+// Hint, the display is 16 rows tall. To scroll the whole display, run:
+// display.scrollright(0x00, 0x0F)
+void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop){
+ ssd1306_command(SSD1306_LEFT_HORIZONTAL_SCROLL);
+ ssd1306_command(0X00);
+ ssd1306_command(start);
+ ssd1306_command(0X00);
+ ssd1306_command(stop);
+ ssd1306_command(0X01);
+ ssd1306_command(0XFF);
+ ssd1306_command(SSD1306_ACTIVATE_SCROLL);
+}
+
+// startscrolldiagright
+// Activate a diagonal scroll for rows start through stop
+// Hint, the display is 16 rows tall. To scroll the whole display, run:
+// display.scrollright(0x00, 0x0F)
+void Adafruit_SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
+ ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA);
+ ssd1306_command(0X00);
+ ssd1306_command(SSD1306_LCDHEIGHT);
+ ssd1306_command(SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL);
+ ssd1306_command(0X00);
+ ssd1306_command(start);
+ ssd1306_command(0X00);
+ ssd1306_command(stop);
+ ssd1306_command(0X01);
+ ssd1306_command(SSD1306_ACTIVATE_SCROLL);
+}
+
+// startscrolldiagleft
+// Activate a diagonal scroll for rows start through stop
+// Hint, the display is 16 rows tall. To scroll the whole display, run:
+// display.scrollright(0x00, 0x0F)
+void Adafruit_SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){
+ ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA);
+ ssd1306_command(0X00);
+ ssd1306_command(SSD1306_LCDHEIGHT);
+ ssd1306_command(SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL);
+ ssd1306_command(0X00);
+ ssd1306_command(start);
+ ssd1306_command(0X00);
+ ssd1306_command(stop);
+ ssd1306_command(0X01);
+ ssd1306_command(SSD1306_ACTIVATE_SCROLL);
+}
+
+void Adafruit_SSD1306::stopscroll(void){
+ ssd1306_command(SSD1306_DEACTIVATE_SCROLL);
+}
+
void Adafruit_SSD1306::ssd1306_data(uint8_t c) {
if (sid != -1)
{
View
20 Adafruit_SSD1306.h
@@ -46,8 +46,8 @@ All text above, and the splash screen must be included in any redistribution
appropriate size
-----------------------------------------------------------------------*/
-// #define SSD1306_128_64
- #define SSD1306_128_32
+ #define SSD1306_128_64
+// #define SSD1306_128_32
/*=========================================================================*/
#if defined SSD1306_128_64 && defined SSD1306_128_32
@@ -101,6 +101,15 @@ All text above, and the splash screen must be included in any redistribution
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
+// Scrolling #defines
+#define SSD1306_ACTIVATE_SCROLL 0x2F
+#define SSD1306_DEACTIVATE_SCROLL 0x2E
+#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
+#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
+#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
+#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
+#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
+
class Adafruit_SSD1306 : public Adafruit_GFX {
public:
Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
@@ -114,6 +123,13 @@ class Adafruit_SSD1306 : public Adafruit_GFX {
void invertDisplay(uint8_t i);
void display();
+ void startscrollright(uint8_t start, uint8_t stop);
+ void startscrollleft(uint8_t start, uint8_t stop);
+
+ void startscrolldiagright(uint8_t start, uint8_t stop);
+ void startscrolldiagleft(uint8_t start, uint8_t stop);
+ void stopscroll(void);
+
void drawPixel(int16_t x, int16_t y, uint16_t color);
private:
View
1  README.txt
@@ -11,6 +11,7 @@ please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
+Scrolling code contributed by Michael Gregg
BSD license, check license.txt for more information
All text above must be included in any redistribution
View
29 examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino
@@ -108,6 +108,11 @@ void setup() {
delay(2000);
display.clearDisplay();
+ // draw scrolling text
+ testscrolltext();
+ delay(2000);
+ display.clearDisplay();
+
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
@@ -304,3 +309,27 @@ void testdrawline() {
}
delay(250);
}
+
+void testscrolltext(void) {
+ display.setTextSize(2);
+ display.setTextColor(WHITE);
+ display.setCursor(10,0);
+ display.clearDisplay();
+ display.println("scroll");
+ display.display();
+
+ display.startscrollright(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrollleft(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrolldiagright(0x00, 0x07);
+ delay(2000);
+ display.startscrolldiagleft(0x00, 0x07);
+ delay(2000);
+ display.stopscroll();
+}
+
View
29 examples/ssd1306_128x32_spi/ssd1306_128x32_spi.ino
@@ -111,6 +111,11 @@ void setup() {
delay(2000);
display.clearDisplay();
+ // draw scrolling text
+ testscrolltext();
+ delay(2000);
+ display.clearDisplay();
+
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
@@ -307,3 +312,27 @@ void testdrawline() {
}
delay(250);
}
+
+void testscrolltext(void) {
+ display.setTextSize(2);
+ display.setTextColor(WHITE);
+ display.setCursor(10,0);
+ display.clearDisplay();
+ display.println("scroll");
+ display.display();
+
+ display.startscrollright(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrollleft(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrolldiagright(0x00, 0x07);
+ delay(2000);
+ display.startscrolldiagleft(0x00, 0x07);
+ delay(2000);
+ display.stopscroll();
+}
+
View
28 examples/ssd1306_128x64_i2c/ssd1306_128x64_i2c.ino
@@ -108,6 +108,11 @@ void setup() {
delay(2000);
display.clearDisplay();
+ // draw scrolling text
+ testscrolltext();
+ delay(2000);
+ display.clearDisplay();
+
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
@@ -304,3 +309,26 @@ void testdrawline() {
}
delay(250);
}
+
+void testscrolltext(void) {
+ display.setTextSize(2);
+ display.setTextColor(WHITE);
+ display.setCursor(10,0);
+ display.clearDisplay();
+ display.println("scroll");
+ display.display();
+
+ display.startscrollright(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrollleft(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrolldiagright(0x00, 0x07);
+ delay(2000);
+ display.startscrolldiagleft(0x00, 0x07);
+ delay(2000);
+ display.stopscroll();
+}
View
29 examples/ssd1306_128x64_spi/ssd1306_128x64_spi.ino
@@ -111,6 +111,11 @@ void setup() {
delay(2000);
display.clearDisplay();
+ // draw scrolling text
+ testscrolltext();
+ delay(2000);
+ display.clearDisplay();
+
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
@@ -307,3 +312,27 @@ void testdrawline() {
}
delay(250);
}
+
+void testscrolltext(void) {
+ display.setTextSize(2);
+ display.setTextColor(WHITE);
+ display.setCursor(10,0);
+ display.clearDisplay();
+ display.println("scroll");
+ display.display();
+
+ display.startscrollright(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrollleft(0x00, 0x0F);
+ delay(2000);
+ display.stopscroll();
+ delay(1000);
+ display.startscrolldiagright(0x00, 0x07);
+ delay(2000);
+ display.startscrolldiagleft(0x00, 0x07);
+ delay(2000);
+ display.stopscroll();
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.