Skip to content

Commit

Permalink
Added rotation and example
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Jul 3, 2012
1 parent 3bdf5a1 commit 2b23a5e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
34 changes: 33 additions & 1 deletion Adafruit_LEDBackpack.cpp
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions examples/bicolor8x8/bicolor8x8.pde
Expand Up @@ -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);
}
15 changes: 12 additions & 3 deletions examples/matrix8x8/matrix8x8.ino
Expand Up @@ -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.