Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added rotation and example

  • Loading branch information...
commit 2b23a5e8e6c1a71854831f67930de1c086f36cff 1 parent 3bdf5a1
@ladyada ladyada authored
View
34 Adafruit_LEDBackpack.cpp
@@ -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) {
View
14 examples/bicolor8x8/bicolor8x8.pde
@@ -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);
}
View
15 examples/matrix8x8/matrix8x8.ino
@@ -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);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.