Permalink
Browse files

Added rotation and example

  • Loading branch information...
1 parent 3bdf5a1 commit 2b23a5e8e6c1a71854831f67930de1c086f36cff @ladyada ladyada committed Jul 3, 2012
Showing with 57 additions and 6 deletions.
  1. +33 −1 Adafruit_LEDBackpack.cpp
  2. +12 −2 examples/bicolor8x8/bicolor8x8.pde
  3. +12 −3 examples/matrix8x8/matrix8x8.ino
View
@@ -98,12 +98,29 @@ Adafruit_8x8matrix::Adafruit_8x8matrix(void) {
void Adafruit_8x8matrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
if ((y < 0) || (y >= 8)) return;
- if ((x < 0) || (x >= 16)) return;
+ if ((x < 0) || (x >= 8)) return;
+
+ // check rotation, move pixel around if necessary
+ switch (getRotation()) {
+ case 1:
+ swap(x, y);
+ x = 8 - x - 1;
+ break;
+ case 2:
+ x = 8 - x - 1;
+ y = 8 - y - 1;
+ break;
+ case 3:
+ swap(x, y);
+ y = 8 - y - 1;
+ break;
+ }
// wrap around the x
x += 7;
x %= 8;
+
if (color) {
displaybuffer[y] |= 1 << x;
} else {
@@ -120,6 +137,21 @@ void Adafruit_BicolorMatrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
if ((y < 0) || (y >= 8)) return;
if ((x < 0) || (x >= 8)) return;
+ switch (getRotation()) {
+ case 1:
+ swap(x, y);
+ x = 8 - x - 1;
+ break;
+ case 2:
+ x = 8 - x - 1;
+ y = 8 - y - 1;
+ break;
+ case 3:
+ swap(x, y);
+ y = 8 - y - 1;
+ break;
+ }
+
if (color == LED_GREEN) {
displaybuffer[y] |= 1 << x;
} else if (color == LED_RED) {
@@ -78,11 +78,21 @@ void loop() {
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix.setTextSize(1);
matrix.setTextColor(LED_GREEN);
- for (int8_t x=7; x>=-66; x--) {
+ for (int8_t x=7; x>=-36; x--) {
matrix.clear();
matrix.setCursor(x,0);
- matrix.print("Hello world");
+ matrix.print("Hello");
matrix.writeDisplay();
delay(100);
}
+ matrix.setRotation(3);
+ matrix.setTextColor(LED_RED);
+ for (int8_t x=7; x>=-36; x--) {
+ matrix.clear();
+ matrix.setCursor(x,0);
+ matrix.print("World");
+ matrix.writeDisplay();
+ delay(100);
+ }
+ matrix.setRotation(0);
}
@@ -77,11 +77,20 @@ void loop() {
matrix.setTextSize(1);
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix.setTextColor(LED_ON);
- for (int8_t x=0; x>=-66; x--) {
+ for (int8_t x=0; x>=-36; x--) {
matrix.clear();
matrix.setCursor(x,0);
- matrix.print("Hello world");
+ matrix.print("Hello");
matrix.writeDisplay();
delay(100);
}
-}
+ matrix.setRotation(3);
+ for (int8_t x=7; x>=-36; x--) {
+ matrix.clear();
+ matrix.setCursor(x,0);
+ matrix.print("World");
+ matrix.writeDisplay();
+ delay(100);
+ }
+ matrix.setRotation(0);
+}

0 comments on commit 2b23a5e

Please sign in to comment.