初始化提交
This commit is contained in:
@@ -0,0 +1,664 @@
|
||||
/*!
|
||||
* @file Adafruit_LEDBackpack.cpp
|
||||
*
|
||||
* @mainpage Adafruit LED Backpack library for Arduino.
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* This is an Arduino library for our I2C LED Backpacks:
|
||||
* ----> http://www.adafruit.com/products/
|
||||
* ----> http://www.adafruit.com/products/
|
||||
*
|
||||
* These displays use I2C to communicate, 2 pins are required to
|
||||
* interface. There are multiple selectable I2C addresses. For backpacks
|
||||
* with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
* with 3 Address Select pins: 0x70 thru 0x77
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* @section dependencies Dependencies
|
||||
*
|
||||
* This library depends on <a
|
||||
* href="https://github.com/adafruit/Adafruit-GFX-Library"> Adafruit_GFX</a>
|
||||
* being present on your system. Please make sure you have installed the latest
|
||||
* version before using this library.
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* MIT license, all text above must be included in any redistribution
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
#ifndef _BV
|
||||
#define _BV(bit) (1 << (bit)) ///< Bit-value if not defined by Arduino
|
||||
#endif
|
||||
|
||||
#ifndef _swap_int16_t
|
||||
#define _swap_int16_t(a, b) \
|
||||
{ \
|
||||
int16_t t = a; \
|
||||
a = b; \
|
||||
b = t; \
|
||||
} ///< 16-bit var swap
|
||||
#endif
|
||||
|
||||
static const uint8_t numbertable[] = {
|
||||
0x3F, /* 0 */
|
||||
0x06, /* 1 */
|
||||
0x5B, /* 2 */
|
||||
0x4F, /* 3 */
|
||||
0x66, /* 4 */
|
||||
0x6D, /* 5 */
|
||||
0x7D, /* 6 */
|
||||
0x07, /* 7 */
|
||||
0x7F, /* 8 */
|
||||
0x6F, /* 9 */
|
||||
0x77, /* a */
|
||||
0x7C, /* b */
|
||||
0x39, /* C */
|
||||
0x5E, /* d */
|
||||
0x79, /* E */
|
||||
0x71, /* F */
|
||||
};
|
||||
|
||||
static const uint16_t alphafonttable[] PROGMEM = {
|
||||
|
||||
0b0000000000000001, 0b0000000000000010, 0b0000000000000100,
|
||||
0b0000000000001000, 0b0000000000010000, 0b0000000000100000,
|
||||
0b0000000001000000, 0b0000000010000000, 0b0000000100000000,
|
||||
0b0000001000000000, 0b0000010000000000, 0b0000100000000000,
|
||||
0b0001000000000000, 0b0010000000000000, 0b0100000000000000,
|
||||
0b1000000000000000, 0b0000000000000000, 0b0000000000000000,
|
||||
0b0000000000000000, 0b0000000000000000, 0b0000000000000000,
|
||||
0b0000000000000000, 0b0000000000000000, 0b0000000000000000,
|
||||
0b0001001011001001, 0b0001010111000000, 0b0001001011111001,
|
||||
0b0000000011100011, 0b0000010100110000, 0b0001001011001000,
|
||||
0b0011101000000000, 0b0001011100000000,
|
||||
0b0000000000000000, //
|
||||
0b0000000000000110, // !
|
||||
0b0000001000100000, // "
|
||||
0b0001001011001110, // #
|
||||
0b0001001011101101, // $
|
||||
0b0000110000100100, // %
|
||||
0b0010001101011101, // &
|
||||
0b0000010000000000, // '
|
||||
0b0010010000000000, // (
|
||||
0b0000100100000000, // )
|
||||
0b0011111111000000, // *
|
||||
0b0001001011000000, // +
|
||||
0b0000100000000000, // ,
|
||||
0b0000000011000000, // -
|
||||
0b0000000000000000, // .
|
||||
0b0000110000000000, // /
|
||||
0b0000110000111111, // 0
|
||||
0b0000000000000110, // 1
|
||||
0b0000000011011011, // 2
|
||||
0b0000000010001111, // 3
|
||||
0b0000000011100110, // 4
|
||||
0b0010000001101001, // 5
|
||||
0b0000000011111101, // 6
|
||||
0b0000000000000111, // 7
|
||||
0b0000000011111111, // 8
|
||||
0b0000000011101111, // 9
|
||||
0b0001001000000000, // :
|
||||
0b0000101000000000, // ;
|
||||
0b0010010000000000, // <
|
||||
0b0000000011001000, // =
|
||||
0b0000100100000000, // >
|
||||
0b0001000010000011, // ?
|
||||
0b0000001010111011, // @
|
||||
0b0000000011110111, // A
|
||||
0b0001001010001111, // B
|
||||
0b0000000000111001, // C
|
||||
0b0001001000001111, // D
|
||||
0b0000000011111001, // E
|
||||
0b0000000001110001, // F
|
||||
0b0000000010111101, // G
|
||||
0b0000000011110110, // H
|
||||
0b0001001000000000, // I
|
||||
0b0000000000011110, // J
|
||||
0b0010010001110000, // K
|
||||
0b0000000000111000, // L
|
||||
0b0000010100110110, // M
|
||||
0b0010000100110110, // N
|
||||
0b0000000000111111, // O
|
||||
0b0000000011110011, // P
|
||||
0b0010000000111111, // Q
|
||||
0b0010000011110011, // R
|
||||
0b0000000011101101, // S
|
||||
0b0001001000000001, // T
|
||||
0b0000000000111110, // U
|
||||
0b0000110000110000, // V
|
||||
0b0010100000110110, // W
|
||||
0b0010110100000000, // X
|
||||
0b0001010100000000, // Y
|
||||
0b0000110000001001, // Z
|
||||
0b0000000000111001, // [
|
||||
0b0010000100000000, //
|
||||
0b0000000000001111, // ]
|
||||
0b0000110000000011, // ^
|
||||
0b0000000000001000, // _
|
||||
0b0000000100000000, // `
|
||||
0b0001000001011000, // a
|
||||
0b0010000001111000, // b
|
||||
0b0000000011011000, // c
|
||||
0b0000100010001110, // d
|
||||
0b0000100001011000, // e
|
||||
0b0000000001110001, // f
|
||||
0b0000010010001110, // g
|
||||
0b0001000001110000, // h
|
||||
0b0001000000000000, // i
|
||||
0b0000000000001110, // j
|
||||
0b0011011000000000, // k
|
||||
0b0000000000110000, // l
|
||||
0b0001000011010100, // m
|
||||
0b0001000001010000, // n
|
||||
0b0000000011011100, // o
|
||||
0b0000000101110000, // p
|
||||
0b0000010010000110, // q
|
||||
0b0000000001010000, // r
|
||||
0b0010000010001000, // s
|
||||
0b0000000001111000, // t
|
||||
0b0000000000011100, // u
|
||||
0b0010000000000100, // v
|
||||
0b0010100000010100, // w
|
||||
0b0010100011000000, // x
|
||||
0b0010000000001100, // y
|
||||
0b0000100001001000, // z
|
||||
0b0000100101001001, // {
|
||||
0b0001001000000000, // |
|
||||
0b0010010010001001, // }
|
||||
0b0000010100100000, // ~
|
||||
0b0011111111111111,
|
||||
|
||||
};
|
||||
void Adafruit_LEDBackpack::setBrightness(uint8_t b) {
|
||||
if (b > 15)
|
||||
b = 15;
|
||||
Wire.beginTransmission(i2c_addr);
|
||||
Wire.write(HT16K33_CMD_BRIGHTNESS | b);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
void Adafruit_LEDBackpack::blinkRate(uint8_t b) {
|
||||
Wire.beginTransmission(i2c_addr);
|
||||
if (b > 3)
|
||||
b = 0; // turn off if not sure
|
||||
|
||||
Wire.write(HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1));
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
Adafruit_LEDBackpack::Adafruit_LEDBackpack(void) {}
|
||||
|
||||
void Adafruit_LEDBackpack::begin(uint8_t _addr) {
|
||||
i2c_addr = _addr;
|
||||
|
||||
Wire.begin();
|
||||
|
||||
Wire.beginTransmission(i2c_addr);
|
||||
Wire.write(0x21); // turn on oscillator
|
||||
Wire.endTransmission();
|
||||
|
||||
// internal RAM powers up with garbage/random values.
|
||||
// ensure internal RAM is cleared before turning on display
|
||||
// this ensures that no garbage pixels show up on the display
|
||||
// when it is turned on.
|
||||
clear();
|
||||
writeDisplay();
|
||||
|
||||
blinkRate(HT16K33_BLINK_OFF);
|
||||
|
||||
setBrightness(15); // max brightness
|
||||
}
|
||||
|
||||
void Adafruit_LEDBackpack::writeDisplay(void) {
|
||||
Wire.beginTransmission(i2c_addr);
|
||||
Wire.write((uint8_t)0x00); // start at address $00
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
Wire.write(displaybuffer[i] & 0xFF);
|
||||
Wire.write(displaybuffer[i] >> 8);
|
||||
}
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
void Adafruit_LEDBackpack::clear(void) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
displaybuffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************* QUAD ALPHANUM OBJECT */
|
||||
|
||||
Adafruit_AlphaNum4::Adafruit_AlphaNum4(void) {}
|
||||
|
||||
void Adafruit_AlphaNum4::writeDigitRaw(uint8_t n, uint16_t bitmask) {
|
||||
displaybuffer[n] = bitmask;
|
||||
}
|
||||
|
||||
void Adafruit_AlphaNum4::writeDigitAscii(uint8_t n, uint8_t a, bool d) {
|
||||
uint16_t font = pgm_read_word(alphafonttable + a);
|
||||
|
||||
displaybuffer[n] = font;
|
||||
|
||||
/*
|
||||
Serial.print(a, DEC);
|
||||
Serial.print(" / '"); Serial.write(a);
|
||||
Serial.print("' = 0x"); Serial.println(font, HEX);
|
||||
*/
|
||||
|
||||
if (d)
|
||||
displaybuffer[n] |= (1 << 14);
|
||||
}
|
||||
|
||||
/******************************* 24 BARGRAPH OBJECT */
|
||||
|
||||
Adafruit_24bargraph::Adafruit_24bargraph(void) {}
|
||||
|
||||
void Adafruit_24bargraph::setBar(uint8_t bar, uint8_t color) {
|
||||
uint16_t a, c;
|
||||
|
||||
if (bar < 12)
|
||||
c = bar / 4;
|
||||
else
|
||||
c = (bar - 12) / 4;
|
||||
|
||||
a = bar % 4;
|
||||
if (bar >= 12)
|
||||
a += 4;
|
||||
|
||||
// Serial.print("Ano = "); Serial.print(a); Serial.print(" Cath = ");
|
||||
// Serial.println(c);
|
||||
if (color == LED_RED) {
|
||||
// Turn on red LED.
|
||||
displaybuffer[c] |= _BV(a);
|
||||
// Turn off green LED.
|
||||
displaybuffer[c] &= ~_BV(a + 8);
|
||||
} else if (color == LED_YELLOW) {
|
||||
// Turn on red and green LED.
|
||||
displaybuffer[c] |= _BV(a) | _BV(a + 8);
|
||||
} else if (color == LED_OFF) {
|
||||
// Turn off red and green LED.
|
||||
displaybuffer[c] &= ~_BV(a) & ~_BV(a + 8);
|
||||
} else if (color == LED_GREEN) {
|
||||
// Turn on green LED.
|
||||
displaybuffer[c] |= _BV(a + 8);
|
||||
// Turn off red LED.
|
||||
displaybuffer[c] &= ~_BV(a);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************* 16x8 MATRIX OBJECT */
|
||||
|
||||
Adafruit_8x16matrix::Adafruit_8x16matrix(void) : Adafruit_GFX(8, 16) {}
|
||||
|
||||
void Adafruit_8x16matrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
|
||||
// check rotation, move pixel around if necessary
|
||||
switch (getRotation()) {
|
||||
case 2:
|
||||
_swap_int16_t(x, y);
|
||||
x = 16 - x - 1;
|
||||
break;
|
||||
case 3:
|
||||
x = 16 - x - 1;
|
||||
y = 8 - y - 1;
|
||||
break;
|
||||
case 0:
|
||||
_swap_int16_t(x, y);
|
||||
y = 8 - y - 1;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
Serial.print("("); Serial.print(x);
|
||||
Serial.print(","); Serial.print(y);
|
||||
Serial.println(")");
|
||||
*/
|
||||
|
||||
if ((y < 0) || (y >= 8))
|
||||
return;
|
||||
if ((x < 0) || (x >= 16))
|
||||
return;
|
||||
|
||||
if (color) {
|
||||
displaybuffer[y] |= 1 << x;
|
||||
} else {
|
||||
displaybuffer[y] &= ~(1 << x);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************* 16x8 MINI MATRIX OBJECT */
|
||||
|
||||
Adafruit_8x16minimatrix::Adafruit_8x16minimatrix(void) : Adafruit_GFX(8, 16) {}
|
||||
|
||||
void Adafruit_8x16minimatrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
|
||||
if ((y < 0) || (x < 0))
|
||||
return;
|
||||
if ((getRotation() % 2 == 0) && ((y >= 16) || (x >= 8)))
|
||||
return;
|
||||
if ((getRotation() % 2 == 1) && ((x >= 16) || (y >= 8)))
|
||||
return;
|
||||
|
||||
// check rotation, move pixel around if necessary
|
||||
switch (getRotation()) {
|
||||
case 2:
|
||||
if (y >= 8) {
|
||||
x += 8;
|
||||
y -= 8;
|
||||
}
|
||||
_swap_int16_t(x, y);
|
||||
break;
|
||||
case 3:
|
||||
x = 16 - x - 1;
|
||||
if (x >= 8) {
|
||||
x -= 8;
|
||||
y += 8;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
y = 16 - y - 1;
|
||||
x = 8 - x - 1;
|
||||
if (y >= 8) {
|
||||
x += 8;
|
||||
y -= 8;
|
||||
}
|
||||
_swap_int16_t(x, y);
|
||||
break;
|
||||
case 1:
|
||||
y = 8 - y - 1;
|
||||
if (x >= 8) {
|
||||
x -= 8;
|
||||
y += 8;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (color) {
|
||||
displaybuffer[x] |= 1 << y;
|
||||
} else {
|
||||
displaybuffer[x] &= ~(1 << y);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************* 8x8 MATRIX OBJECT */
|
||||
|
||||
Adafruit_8x8matrix::Adafruit_8x8matrix(void) : Adafruit_GFX(8, 8) {}
|
||||
|
||||
void Adafruit_8x8matrix::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if ((y < 0) || (y >= 8))
|
||||
return;
|
||||
if ((x < 0) || (x >= 8))
|
||||
return;
|
||||
|
||||
// check rotation, move pixel around if necessary
|
||||
switch (getRotation()) {
|
||||
case 1:
|
||||
_swap_int16_t(x, y);
|
||||
x = 8 - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = 8 - x - 1;
|
||||
y = 8 - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
_swap_int16_t(x, y);
|
||||
y = 8 - y - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// wrap around the x
|
||||
x += 7;
|
||||
x %= 8;
|
||||
|
||||
if (color) {
|
||||
displaybuffer[y] |= 1 << x;
|
||||
} else {
|
||||
displaybuffer[y] &= ~(1 << x);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************* 8x8 BICOLOR MATRIX OBJECT */
|
||||
|
||||
Adafruit_BicolorMatrix::Adafruit_BicolorMatrix(void) : Adafruit_GFX(8, 8) {}
|
||||
|
||||
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_int16_t(x, y);
|
||||
x = 8 - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = 8 - x - 1;
|
||||
y = 8 - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
_swap_int16_t(x, y);
|
||||
y = 8 - y - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (color == LED_GREEN) {
|
||||
// Turn on green LED.
|
||||
displaybuffer[y] |= 1 << x;
|
||||
// Turn off red LED.
|
||||
displaybuffer[y] &= ~(1 << (x + 8));
|
||||
} else if (color == LED_RED) {
|
||||
// Turn on red LED.
|
||||
displaybuffer[y] |= 1 << (x + 8);
|
||||
// Turn off green LED.
|
||||
displaybuffer[y] &= ~(1 << x);
|
||||
} else if (color == LED_YELLOW) {
|
||||
// Turn on green and red LED.
|
||||
displaybuffer[y] |= (1 << (x + 8)) | (1 << x);
|
||||
} else if (color == LED_OFF) {
|
||||
// Turn off green and red LED.
|
||||
displaybuffer[y] &= ~(1 << x) & ~(1 << (x + 8));
|
||||
}
|
||||
}
|
||||
|
||||
/******************************* 7 SEGMENT OBJECT */
|
||||
|
||||
Adafruit_7segment::Adafruit_7segment(void) { position = 0; }
|
||||
|
||||
void Adafruit_7segment::print(unsigned long n, int base) {
|
||||
if (base == 0)
|
||||
write(n);
|
||||
else
|
||||
printNumber(n, base);
|
||||
}
|
||||
|
||||
void Adafruit_7segment::print(char c, int base) { print((long)c, base); }
|
||||
|
||||
void Adafruit_7segment::print(unsigned char b, int base) {
|
||||
print((unsigned long)b, base);
|
||||
}
|
||||
|
||||
void Adafruit_7segment::print(int n, int base) { print((long)n, base); }
|
||||
|
||||
void Adafruit_7segment::print(unsigned int n, int base) {
|
||||
print((unsigned long)n, base);
|
||||
}
|
||||
|
||||
void Adafruit_7segment::println(void) { position = 0; }
|
||||
|
||||
void Adafruit_7segment::println(char c, int base) {
|
||||
print(c, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::println(unsigned char b, int base) {
|
||||
print(b, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::println(int n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::println(unsigned int n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::println(long n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::println(unsigned long n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::println(double n, int digits) {
|
||||
print(n, digits);
|
||||
println();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::print(double n, int digits) { printFloat(n, digits); }
|
||||
|
||||
size_t Adafruit_7segment::write(uint8_t c) {
|
||||
|
||||
uint8_t r = 0;
|
||||
|
||||
if (c == '\n')
|
||||
position = 0;
|
||||
if (c == '\r')
|
||||
position = 0;
|
||||
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
writeDigitNum(position, c - '0');
|
||||
r = 1;
|
||||
}
|
||||
|
||||
position++;
|
||||
if (position == 2)
|
||||
position++;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void Adafruit_7segment::writeDigitRaw(uint8_t d, uint8_t bitmask) {
|
||||
if (d > 4)
|
||||
return;
|
||||
displaybuffer[d] = bitmask;
|
||||
}
|
||||
|
||||
void Adafruit_7segment::drawColon(bool state) {
|
||||
if (state)
|
||||
displaybuffer[2] = 0x2;
|
||||
else
|
||||
displaybuffer[2] = 0;
|
||||
}
|
||||
|
||||
void Adafruit_7segment::writeColon(void) {
|
||||
Wire.beginTransmission(i2c_addr);
|
||||
Wire.write((uint8_t)0x04); // start at address $02
|
||||
|
||||
Wire.write(displaybuffer[2] & 0xFF);
|
||||
Wire.write(displaybuffer[2] >> 8);
|
||||
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
void Adafruit_7segment::writeDigitNum(uint8_t d, uint8_t num, bool dot) {
|
||||
if (d > 4)
|
||||
return;
|
||||
|
||||
writeDigitRaw(d, numbertable[num] | (dot << 7));
|
||||
}
|
||||
|
||||
void Adafruit_7segment::print(long n, int base) { printNumber(n, base); }
|
||||
|
||||
void Adafruit_7segment::printNumber(long n, uint8_t base) {
|
||||
printFloat(n, 0, base);
|
||||
}
|
||||
|
||||
void Adafruit_7segment::printFloat(double n, uint8_t fracDigits, uint8_t base) {
|
||||
uint8_t numericDigits = 4; // available digits on display
|
||||
bool isNegative = false; // true if the number is negative
|
||||
|
||||
// is the number negative?
|
||||
if (n < 0) {
|
||||
isNegative = true; // need to draw sign later
|
||||
--numericDigits; // the sign will take up one digit
|
||||
n *= -1; // pretend the number is positive
|
||||
}
|
||||
|
||||
// calculate the factor required to shift all fractional digits
|
||||
// into the integer part of the number
|
||||
double toIntFactor = 1.0;
|
||||
for (int i = 0; i < fracDigits; ++i)
|
||||
toIntFactor *= base;
|
||||
|
||||
// create integer containing digits to display by applying
|
||||
// shifting factor and rounding adjustment
|
||||
uint32_t displayNumber = n * toIntFactor + 0.5;
|
||||
|
||||
// calculate upper bound on displayNumber given
|
||||
// available digits on display
|
||||
uint32_t tooBig = 1;
|
||||
for (int i = 0; i < numericDigits; ++i)
|
||||
tooBig *= base;
|
||||
|
||||
// if displayNumber is too large, try fewer fractional digits
|
||||
while (displayNumber >= tooBig) {
|
||||
--fracDigits;
|
||||
toIntFactor /= base;
|
||||
displayNumber = n * toIntFactor + 0.5;
|
||||
}
|
||||
|
||||
// did toIntFactor shift the decimal off the display?
|
||||
if (toIntFactor < 1) {
|
||||
printError();
|
||||
} else {
|
||||
// otherwise, display the number
|
||||
int8_t displayPos = 4;
|
||||
|
||||
if (displayNumber) // if displayNumber is not 0
|
||||
{
|
||||
for (uint8_t i = 0; displayNumber || i <= fracDigits; ++i) {
|
||||
bool displayDecimal = (fracDigits != 0 && i == fracDigits);
|
||||
writeDigitNum(displayPos--, displayNumber % base, displayDecimal);
|
||||
if (displayPos == 2)
|
||||
writeDigitRaw(displayPos--, 0x00);
|
||||
displayNumber /= base;
|
||||
}
|
||||
} else {
|
||||
writeDigitNum(displayPos--, 0, false);
|
||||
}
|
||||
|
||||
// display negative sign if negative
|
||||
if (isNegative)
|
||||
writeDigitRaw(displayPos--, 0x40);
|
||||
|
||||
// clear remaining display positions
|
||||
while (displayPos >= 0)
|
||||
writeDigitRaw(displayPos--, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_7segment::printError(void) {
|
||||
for (uint8_t i = 0; i < SEVENSEG_DIGITS; ++i) {
|
||||
writeDigitRaw(i, (i == 2 ? 0x00 : 0x40));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,413 @@
|
||||
/*!
|
||||
* @file Adafruit_LEDBackpack.h
|
||||
*
|
||||
* Part of Adafruit's Arduino library for our I2C LED Backpacks:
|
||||
* ----> http://www.adafruit.com/products/
|
||||
* ----> http://www.adafruit.com/products/
|
||||
*
|
||||
* These displays use I2C to communicate, 2 pins are required to
|
||||
* interface. There are multiple selectable I2C addresses. For backpacks
|
||||
* with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
* with 3 Address Select pins: 0x70 thru 0x77
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* MIT license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#ifndef Adafruit_LEDBackpack_h
|
||||
#define Adafruit_LEDBackpack_h
|
||||
|
||||
#if (ARDUINO >= 100)
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
|
||||
#define LED_ON 1 ///< GFX color of lit LED segments (single-color displays)
|
||||
#define LED_OFF 0 ///< GFX color of unlit LED segments (single-color displays)
|
||||
|
||||
#define LED_RED 1 ///< GFX color for red LED segments (bi-color displays)
|
||||
#define LED_YELLOW 2 ///< GFX color for yellow LED segments (bi-color displays)
|
||||
#define LED_GREEN 3 ///< GFX color for green LED segments (bi-color displays)
|
||||
|
||||
#define HT16K33_BLINK_CMD 0x80 ///< I2C register for BLINK setting
|
||||
#define HT16K33_BLINK_DISPLAYON 0x01 ///< I2C value for steady on
|
||||
#define HT16K33_BLINK_OFF 0 ///< I2C value for steady off
|
||||
#define HT16K33_BLINK_2HZ 1 ///< I2C value for 2 Hz blink
|
||||
#define HT16K33_BLINK_1HZ 2 ///< I2C value for 1 Hz blink
|
||||
#define HT16K33_BLINK_HALFHZ 3 ///< I2C value for 0.5 Hz blink
|
||||
|
||||
#define HT16K33_CMD_BRIGHTNESS 0xE0 ///< I2C register for BRIGHTNESS setting
|
||||
|
||||
#define SEVENSEG_DIGITS 5 ///< # Digits in 7-seg displays, plus NUL end
|
||||
|
||||
/*!
|
||||
@brief Class encapsulating the raw HT16K33 controller device.
|
||||
*/
|
||||
class Adafruit_LEDBackpack {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for HT16K33 devices.
|
||||
*/
|
||||
Adafruit_LEDBackpack(void);
|
||||
|
||||
/*!
|
||||
@brief Start I2C and initialize display state (blink off, full
|
||||
brightness).
|
||||
@param _addr I2C address.
|
||||
*/
|
||||
void begin(uint8_t _addr = 0x70);
|
||||
|
||||
/*!
|
||||
@brief Set display brightness.
|
||||
@param b Brightness: 0 (min) to 15 (max).
|
||||
*/
|
||||
void setBrightness(uint8_t b);
|
||||
|
||||
/*!
|
||||
@brief Set display blink rate.
|
||||
@param b One of:
|
||||
HT16K33_BLINK_DISPLAYON = steady on
|
||||
HT16K33_BLINK_OFF = steady off
|
||||
HT16K33_BLINK_2HZ = 2 Hz blink
|
||||
HT16K33_BLINK_1HZ = 1 Hz blink
|
||||
HT16K33_BLINK_HALFHZ = 0.5 Hz blink
|
||||
*/
|
||||
void blinkRate(uint8_t b);
|
||||
|
||||
/*!
|
||||
@brief Issue buffered data in RAM to display.
|
||||
*/
|
||||
void writeDisplay(void);
|
||||
|
||||
/*!
|
||||
@brief Clear display.
|
||||
*/
|
||||
void clear(void);
|
||||
|
||||
uint16_t displaybuffer[8]; ///< Raw display data
|
||||
|
||||
protected:
|
||||
uint8_t i2c_addr; ///< Device I2C address
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Class for 24-element bargraph displays.
|
||||
*/
|
||||
class Adafruit_24bargraph : public Adafruit_LEDBackpack {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for 24-element bargraph displays.
|
||||
*/
|
||||
Adafruit_24bargraph(void);
|
||||
|
||||
/*!
|
||||
@brief Set color a single bar (dot).
|
||||
@param bar Bar index (0 to 23).
|
||||
@param color Bar color: LED_OFF, LED_GREEN, LED_YELLOW or LED_RED.
|
||||
*/
|
||||
void setBar(uint8_t bar, uint8_t color);
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Class for 8x16 pixel single-color matrices.
|
||||
*/
|
||||
class Adafruit_8x16matrix : public Adafruit_LEDBackpack, public Adafruit_GFX {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for 8x16 pixel single-color matrices.
|
||||
*/
|
||||
Adafruit_8x16matrix(void);
|
||||
|
||||
/*!
|
||||
@brief Lowest-level pixel drawing function required by Adafruit_GFX.
|
||||
Does not have an immediate effect -- must call writeDisplay()
|
||||
after any drawing operations to refresh display contents.
|
||||
@param x Pixel column (horizontal).
|
||||
@param y Pixel row (vertical).
|
||||
@param color Pixel color (1 = pixel on, 0 = pixel off).
|
||||
*/
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Class for 8x16 pixel single-color mini matrices.
|
||||
*/
|
||||
class Adafruit_8x16minimatrix : public Adafruit_LEDBackpack,
|
||||
public Adafruit_GFX {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for 8x16 pixel single-color mini matrices.
|
||||
*/
|
||||
Adafruit_8x16minimatrix(void);
|
||||
|
||||
/*!
|
||||
@brief Lowest-level pixel drawing function required by Adafruit_GFX.
|
||||
Does not have an immediate effect -- must call writeDisplay()
|
||||
after any drawing operations to refresh display contents.
|
||||
@param x Pixel column (horizontal).
|
||||
@param y Pixel row (vertical).
|
||||
@param color Pixel color (1 = pixel on, 0 = pixel off).
|
||||
*/
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Class for 8x8 pixel single-color matrices.
|
||||
*/
|
||||
class Adafruit_8x8matrix : public Adafruit_LEDBackpack, public Adafruit_GFX {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for 8x8 pixel single-color matrices.
|
||||
*/
|
||||
Adafruit_8x8matrix(void);
|
||||
|
||||
/*!
|
||||
@brief Lowest-level pixel drawing function required by Adafruit_GFX.
|
||||
Does not have an immediate effect -- must call writeDisplay()
|
||||
after any drawing operations to refresh display contents.
|
||||
@param x Pixel column (horizontal).
|
||||
@param y Pixel row (vertical).
|
||||
@param color Pixel color (1 = pixel on, 0 = pixel off).
|
||||
*/
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Class for bi-color matrices.
|
||||
*/
|
||||
class Adafruit_BicolorMatrix : public Adafruit_LEDBackpack,
|
||||
public Adafruit_GFX {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for 8x8 pixel bi-color matrices.
|
||||
*/
|
||||
Adafruit_BicolorMatrix(void);
|
||||
|
||||
/*!
|
||||
@brief Lowest-level pixel drawing function required by Adafruit_GFX.
|
||||
Does not have an immediate effect -- must call writeDisplay()
|
||||
after any drawing operations to refresh display contents.
|
||||
@param x Pixel column (horizontal).
|
||||
@param y Pixel row (vertical).
|
||||
@param color Pixel color (LED_OFF, LED_GREEN, LED_YELLOW or LED_RED).
|
||||
*/
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
};
|
||||
|
||||
#define DEC 10 ///< Print value in decimal format (base 10)
|
||||
#define HEX 16 ///< Print value in hexadecimal format (base 16)
|
||||
#define OCT 8 ///< Print value in octal format (base 8)
|
||||
#define BIN 2 ///< Print value in binary format (base 2)
|
||||
#define BYTE 0 ///< Issue 7-segment data as raw bits
|
||||
|
||||
/*!
|
||||
@brief Class for 7-segment numeric displays.
|
||||
*/
|
||||
class Adafruit_7segment : public Adafruit_LEDBackpack {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for 7-segment numeric displays.
|
||||
*/
|
||||
Adafruit_7segment(void);
|
||||
|
||||
/*!
|
||||
@brief Issue single digit to display.
|
||||
@param c Digit to write (ASCII character, not numeric).
|
||||
@return 1 if character written, else 0 (non-digit characters).
|
||||
*/
|
||||
size_t write(uint8_t c);
|
||||
|
||||
/*!
|
||||
@brief Print byte-size numeric value to 7-segment display.
|
||||
@param c Numeric value.
|
||||
@param base Number base (default = BYTE = raw bits)
|
||||
*/
|
||||
void print(char c, int base = BYTE);
|
||||
|
||||
/*!
|
||||
@brief Print unsigned byte-size numeric value to 7-segment display.
|
||||
@param b Numeric value.
|
||||
@param base Number base (default = BYTE = raw bits)
|
||||
*/
|
||||
void print(unsigned char b, int base = BYTE);
|
||||
|
||||
/*!
|
||||
@brief Print integer value to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void print(int n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print unsigned integer value to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void print(unsigned int n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print long integer value to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void print(long n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print unsigned long integer value to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void print(unsigned long n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print double-precision float value to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param digits Fractional-part digits.
|
||||
*/
|
||||
void print(double n, int digits = 2);
|
||||
|
||||
/*!
|
||||
@brief Print byte-size numeric value w/newline to 7-segment display.
|
||||
@param c Numeric value.
|
||||
@param base Number base (default = BYTE = raw bits)
|
||||
*/
|
||||
void println(char c, int base = BYTE);
|
||||
|
||||
/*!
|
||||
@brief Print unsigned byte-size numeric value w/newline to 7-segment
|
||||
display.
|
||||
@param b Numeric value.
|
||||
@param base Number base (default = BYTE = raw bits)
|
||||
*/
|
||||
void println(unsigned char b, int base = BYTE);
|
||||
|
||||
/*!
|
||||
@brief Print integer value with newline to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void println(int n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print unsigned integer value with newline to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void println(unsigned int n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print long integer value with newline to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void println(long n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print unsigned long integer value w/newline to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param base Number base (default = DEC = base 10)
|
||||
*/
|
||||
void println(unsigned long n, int base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Print double-precision float value to 7-segment display.
|
||||
@param n Numeric value.
|
||||
@param digits Fractional-part digits.
|
||||
*/
|
||||
void println(double n, int digits = 2);
|
||||
|
||||
/*!
|
||||
@brief Print newline to 7-segment display (rewind position to start).
|
||||
*/
|
||||
void println(void);
|
||||
|
||||
/*!
|
||||
@brief Write raw segment bits into display buffer.
|
||||
@param x Character position (0-3).
|
||||
@param bitmask Segment bits.
|
||||
*/
|
||||
void writeDigitRaw(uint8_t x, uint8_t bitmask);
|
||||
|
||||
/*!
|
||||
@brief Set specific digit # to a numeric value.
|
||||
@param x Character position.
|
||||
@param num Numeric (not ASCII) value.
|
||||
@param dot If true, light corresponding decimal.
|
||||
*/
|
||||
void writeDigitNum(uint8_t x, uint8_t num, bool dot = false);
|
||||
|
||||
/*!
|
||||
@brief Set or unset colon segment.
|
||||
@param state 'true' to enable colon, 'false' for off.
|
||||
*/
|
||||
void drawColon(bool state);
|
||||
|
||||
/*!
|
||||
@brief General integer-printing function used by some of the print()
|
||||
variants.
|
||||
@param n Numeric value.
|
||||
@param base Base (2 = binary).
|
||||
*/
|
||||
void printNumber(long n, uint8_t base = 2);
|
||||
|
||||
/*!
|
||||
@brief General float-printing function used by some of the print()
|
||||
variants.
|
||||
@param n Numeric value.
|
||||
@param fracDigits Fractional-part digits.
|
||||
@param base Base (default DEC = base 10).
|
||||
*/
|
||||
void printFloat(double n, uint8_t fracDigits = 2, uint8_t base = DEC);
|
||||
|
||||
/*!
|
||||
@brief Light display segments in an error-indicating configuration.
|
||||
*/
|
||||
void printError(void);
|
||||
|
||||
/*!
|
||||
@brief Issue colon-on directly to display (bypass buffer).
|
||||
*/
|
||||
void writeColon(void);
|
||||
|
||||
private:
|
||||
uint8_t position; ///< Current print position, 0-3
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Class for four-digit alphanumeric displays.
|
||||
*/
|
||||
class Adafruit_AlphaNum4 : public Adafruit_LEDBackpack {
|
||||
public:
|
||||
/*!
|
||||
@brief Constructor for four-digit alphanumeric displays.
|
||||
*/
|
||||
Adafruit_AlphaNum4(void);
|
||||
|
||||
/*!
|
||||
@brief Write single character of alphanumeric display as raw bits
|
||||
(not a general print function).
|
||||
@param n Character index (0-3).
|
||||
@param bitmask Segment bitmask.
|
||||
*/
|
||||
void writeDigitRaw(uint8_t n, uint16_t bitmask);
|
||||
|
||||
/*!
|
||||
@brief Write single ASCII character to alphanumeric display.
|
||||
@param n Character index (0-3).
|
||||
@param ascii ASCII character.
|
||||
@param dot If true, also light corresponding dot segment.
|
||||
*/
|
||||
void writeDigitAscii(uint8_t n, uint8_t ascii, bool dot = false);
|
||||
};
|
||||
|
||||
#endif // Adafruit_LEDBackpack_h
|
||||
@@ -0,0 +1,30 @@
|
||||
# Adafruit-LED-Backpack-Library [](https://github.com/adafruit/Adafruit_LED_Backpack/actions)
|
||||
<!-- START COMPATIBILITY TABLE -->
|
||||
|
||||
## Compatibility
|
||||
|
||||
MCU | Tested Works | Doesn't Work | Not Tested | Notes
|
||||
----------------- | :----------: | :----------: | :---------: | -----
|
||||
Atmega328 @ 16MHz | X | | |
|
||||
Atmega328 @ 12MHz | X | | |
|
||||
Atmega32u4 @ 16MHz | X | | |
|
||||
Atmega32u4 @ 8MHz | X | | |
|
||||
ESP8266 | X | | |
|
||||
Atmega2560 @ 16MHz | X | | |
|
||||
ATSAM3X8E | X | | | Use SDA/SCL on pins 20 & 21
|
||||
ATSAM21D | X | | |
|
||||
ATtiny85 @ 16MHz | X | | | Use 0 for SDA, 2 for SCL, examples may need Serial references removed
|
||||
ATtiny85 @ 8MHz | X | | | Use 0 for SDA, 2 for SCL, examples may need Serial references removed
|
||||
|
||||
* ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
|
||||
* ATmega328 @ 12MHz : Adafruit Pro Trinket 3V
|
||||
* ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0
|
||||
* ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro
|
||||
* ESP8266 : Adafruit Huzzah
|
||||
* ATmega2560 @ 16MHz : Arduino Mega
|
||||
* ATSAM3X8E : Arduino Due
|
||||
* ATSAM21D : Arduino Zero, M0 Pro
|
||||
* ATtiny85 @ 16MHz : Adafruit Trinket 5V
|
||||
* ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V
|
||||
|
||||
<!-- END COMPATIBILITY TABLE -->
|
||||
@@ -0,0 +1,55 @@
|
||||
/***************************************************
|
||||
This is a library for our I2C LED Backpacks
|
||||
|
||||
Designed specifically to work with the Adafruit LED Matrix backpacks
|
||||
----> http://www.adafruit.com/products/872
|
||||
----> http://www.adafruit.com/products/871
|
||||
----> http://www.adafruit.com/products/870
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface. There are multiple selectable I2C addresses. For backpacks
|
||||
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
with 3 Address Select pins: 0x70 thru 0x77
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
#ifndef _BV
|
||||
#define _BV(bit) (1<<(bit))
|
||||
#endif
|
||||
|
||||
|
||||
Adafruit_LEDBackpack matrix = Adafruit_LEDBackpack();
|
||||
|
||||
uint8_t counter = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("HT16K33 test");
|
||||
|
||||
matrix.begin(0x70); // pass in the address
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// paint one LED per row. The HT16K33 internal memory looks like
|
||||
// a 8x16 bit matrix (8 rows, 16 columns)
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
// draw a diagonal row of pixels
|
||||
matrix.displaybuffer[i] = _BV((counter+i) % 16) | _BV((counter+i+8) % 16) ;
|
||||
}
|
||||
// write the changes we just made to the display
|
||||
matrix.writeDisplay();
|
||||
delay(100);
|
||||
|
||||
counter++;
|
||||
if (counter >= 16) counter = 0;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/***************************************************
|
||||
This is a library for our I2C LED Backpacks
|
||||
|
||||
Designed specifically to work with the Adafruit LED 24 Bargraph Backpack
|
||||
----> http://www.adafruit.com/products/721
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface. There are multiple selectable I2C addresses. For backpacks
|
||||
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
with 3 Address Select pins: 0x70 thru 0x77
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
Adafruit_24bargraph bar = Adafruit_24bargraph();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("HT16K33 Bi-Color Bargraph test");
|
||||
|
||||
bar.begin(0x70); // pass in the address
|
||||
|
||||
for (uint8_t b=0; b<24; b++ ){
|
||||
if ((b % 3) == 0) bar.setBar(b, LED_RED);
|
||||
if ((b % 3) == 1) bar.setBar(b, LED_YELLOW);
|
||||
if ((b % 3) == 2) bar.setBar(b, LED_GREEN);
|
||||
}
|
||||
bar.writeDisplay();
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
for (uint8_t b=0; b<24; b++) {
|
||||
bar.setBar(b, LED_RED);
|
||||
bar.writeDisplay();
|
||||
delay(50);
|
||||
bar.setBar(b, LED_OFF);
|
||||
bar.writeDisplay();
|
||||
}
|
||||
for (uint8_t b=0; b<24; b++) {
|
||||
bar.setBar(b, LED_GREEN);
|
||||
bar.writeDisplay();
|
||||
delay(50);
|
||||
bar.setBar(b, LED_OFF);
|
||||
bar.writeDisplay();
|
||||
}
|
||||
|
||||
for (uint8_t b=0; b<24; b++) {
|
||||
bar.setBar(23-b, LED_YELLOW);
|
||||
bar.writeDisplay();
|
||||
delay(50);
|
||||
bar.setBar(23-b, LED_OFF);
|
||||
bar.writeDisplay();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/***************************************************
|
||||
This is a library for our I2C LED Backpacks
|
||||
|
||||
Designed specifically to work with the Adafruit LED Matrix backpacks
|
||||
----> http://www.adafruit.com/products/872
|
||||
----> http://www.adafruit.com/products/871
|
||||
----> http://www.adafruit.com/products/870
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface. There are multiple selectable I2C addresses. For backpacks
|
||||
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
with 3 Address Select pins: 0x70 thru 0x77
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("8x8 LED Matrix Test");
|
||||
|
||||
matrix.begin(0x70); // pass in the address
|
||||
}
|
||||
|
||||
static const uint8_t PROGMEM
|
||||
smile_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10100101,
|
||||
B10011001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
neutral_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10111101,
|
||||
B10000001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
frown_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10011001,
|
||||
B10100101,
|
||||
B01000010,
|
||||
B00111100 };
|
||||
|
||||
void loop() {
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_GREEN);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, neutral_bmp, 8, 8, LED_YELLOW);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_RED);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear(); // clear display
|
||||
matrix.drawPixel(0, 0, LED_GREEN);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawLine(0,0, 7,7, LED_YELLOW);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawRect(0,0, 8,8, LED_RED);
|
||||
matrix.fillRect(2,2, 4,4, LED_GREEN);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawCircle(3,3, 3, LED_YELLOW);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
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>=-36; x--) {
|
||||
matrix.clear();
|
||||
matrix.setCursor(x,0);
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
// Clock example using a seven segment display & DS1307 real-time clock.
|
||||
//
|
||||
// Must have the Adafruit RTClib library installed too! See:
|
||||
// https://github.com/adafruit/RTClib
|
||||
//
|
||||
// Designed specifically to work with the Adafruit LED 7-Segment backpacks
|
||||
// and DS1307 real-time clock breakout:
|
||||
// ----> http://www.adafruit.com/products/881
|
||||
// ----> http://www.adafruit.com/products/880
|
||||
// ----> http://www.adafruit.com/products/879
|
||||
// ----> http://www.adafruit.com/products/878
|
||||
// ----> https://www.adafruit.com/products/264
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code,
|
||||
// please support Adafruit and open-source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Tony DiCola for Adafruit Industries.
|
||||
// Released under a MIT license: https://opensource.org/licenses/MIT
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <RTClib.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
|
||||
// Set to false to display time in 12 hour format, or true to use 24 hour:
|
||||
#define TIME_24_HOUR false
|
||||
|
||||
// I2C address of the display. Stick with the default address of 0x70
|
||||
// unless you've changed the address jumpers on the back of the display.
|
||||
#define DISPLAY_ADDRESS 0x70
|
||||
|
||||
|
||||
// Create display and DS1307 objects. These are global variables that
|
||||
// can be accessed from both the setup and loop function below.
|
||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||
RTC_DS1307 rtc = RTC_DS1307();
|
||||
|
||||
// Keep track of the hours, minutes, seconds displayed by the clock.
|
||||
// Start off at 0:00:00 as a signal that the time should be read from
|
||||
// the DS1307 to initialize it.
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
|
||||
// Remember if the colon was drawn on the display so it can be blinked
|
||||
// on and off every second.
|
||||
bool blinkColon = false;
|
||||
|
||||
|
||||
void setup() {
|
||||
// Setup function runs once at startup to initialize the display
|
||||
// and DS1307 clock.
|
||||
|
||||
// Setup Serial port to print debug output.
|
||||
Serial.begin(115200);
|
||||
Serial.println("Clock starting!");
|
||||
|
||||
// Setup the display.
|
||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||
|
||||
// Setup the DS1307 real-time clock.
|
||||
rtc.begin();
|
||||
|
||||
// Set the DS1307 clock if it hasn't been set before.
|
||||
bool setClockTime = !rtc.isrunning();
|
||||
// Alternatively you can force the clock to be set again by
|
||||
// uncommenting this line:
|
||||
//setClockTime = true;
|
||||
if (setClockTime) {
|
||||
Serial.println("Setting DS1307 time!");
|
||||
// This line sets the DS1307 time to the exact date and time the
|
||||
// sketch was compiled:
|
||||
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
|
||||
// Alternatively you can set the RTC with an explicit date & time,
|
||||
// for example to set January 21, 2014 at 3am you would uncomment:
|
||||
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Loop function runs over and over again to implement the clock logic.
|
||||
|
||||
// Check if it's the top of the hour and get a new time reading
|
||||
// from the DS1307. This helps keep the clock accurate by fixing
|
||||
// any drift.
|
||||
if (minutes == 0) {
|
||||
// Get the time from the DS1307.
|
||||
DateTime now = rtc.now();
|
||||
// Print out the time for debug purposes:
|
||||
Serial.print("Read date & time from DS1307: ");
|
||||
Serial.print(now.year(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.month(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.day(), DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(now.hour(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.minute(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.second(), DEC);
|
||||
Serial.println();
|
||||
// Now set the hours and minutes.
|
||||
hours = now.hour();
|
||||
minutes = now.minute();
|
||||
}
|
||||
|
||||
// Show the time on the display by turning it into a numeric
|
||||
// value, like 3:30 turns into 330, by multiplying the hour by
|
||||
// 100 and then adding the minutes.
|
||||
int displayValue = hours*100 + minutes;
|
||||
|
||||
// Do 24 hour to 12 hour format conversion when required.
|
||||
if (!TIME_24_HOUR) {
|
||||
// Handle when hours are past 12 by subtracting 12 hours (1200 value).
|
||||
if (hours > 12) {
|
||||
displayValue -= 1200;
|
||||
}
|
||||
// Handle hour 0 (midnight) being shown as 12.
|
||||
else if (hours == 0) {
|
||||
displayValue += 1200;
|
||||
}
|
||||
}
|
||||
|
||||
// Now print the time value to the display.
|
||||
clockDisplay.print(displayValue, DEC);
|
||||
|
||||
// Add zero padding when in 24 hour mode and it's midnight.
|
||||
// In this case the print function above won't have leading 0's
|
||||
// which can look confusing. Go in and explicitly add these zeros.
|
||||
if (TIME_24_HOUR && hours == 0) {
|
||||
// Pad hour 0.
|
||||
clockDisplay.writeDigitNum(1, 0);
|
||||
// Also pad when the 10's minute is 0 and should be padded.
|
||||
if (minutes < 10) {
|
||||
clockDisplay.writeDigitNum(2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Blink the colon by flipping its value every loop iteration
|
||||
// (which happens every second).
|
||||
blinkColon = !blinkColon;
|
||||
clockDisplay.drawColon(blinkColon);
|
||||
|
||||
// Now push out to the display the new values that were set above.
|
||||
clockDisplay.writeDisplay();
|
||||
|
||||
// Pause for a second for time to elapse. This value is in milliseconds
|
||||
// so 1000 milliseconds = 1 second.
|
||||
delay(1000);
|
||||
|
||||
// Now increase the seconds by one.
|
||||
seconds += 1;
|
||||
// If the seconds go above 59 then the minutes should increase and
|
||||
// the seconds should wrap back to 0.
|
||||
if (seconds > 59) {
|
||||
seconds = 0;
|
||||
minutes += 1;
|
||||
// Again if the minutes go above 59 then the hour should increase and
|
||||
// the minutes should wrap back to 0.
|
||||
if (minutes > 59) {
|
||||
minutes = 0;
|
||||
hours += 1;
|
||||
// Note that when the minutes are 0 (i.e. it's the top of a new hour)
|
||||
// then the start of the loop will read the actual time from the DS1307
|
||||
// again. Just to be safe though we'll also increment the hour and wrap
|
||||
// back to 0 if it goes above 23 (i.e. past midnight).
|
||||
if (hours > 23) {
|
||||
hours = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loop code is finished, it will jump back to the start of the loop
|
||||
// function again!
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// Clock example using a seven segment display & GPS for time.
|
||||
//
|
||||
// Must have the Adafruit GPS library installed too! See:
|
||||
// https://github.com/adafruit/Adafruit-GPS-Library
|
||||
//
|
||||
// Designed specifically to work with the Adafruit LED 7-Segment backpacks
|
||||
// and ultimate GPS breakout/shield:
|
||||
// ----> http://www.adafruit.com/products/881
|
||||
// ----> http://www.adafruit.com/products/880
|
||||
// ----> http://www.adafruit.com/products/879
|
||||
// ----> http://www.adafruit.com/products/878
|
||||
// ----> http://www.adafruit.com/products/746
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code,
|
||||
// please support Adafruit and open-source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Tony DiCola for Adafruit Industries.
|
||||
// Released under a MIT license: https://opensource.org/licenses/MIT
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_GPS.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
|
||||
// Set to false to display time in 12 hour format, or true to use 24 hour:
|
||||
#define TIME_24_HOUR false
|
||||
|
||||
// Offset the hours from UTC (universal time) to your local time by changing
|
||||
// this value. The GPS time will be in UTC so lookup the offset for your
|
||||
// local time from a site like:
|
||||
// https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
|
||||
// This value, -7, will set the time to UTC-7 or Pacific Standard Time during
|
||||
// daylight savings time.
|
||||
#define HOUR_OFFSET -7
|
||||
|
||||
// I2C address of the display. Stick with the default address of 0x70
|
||||
// unless you've changed the address jumpers on the back of the display.
|
||||
#define DISPLAY_ADDRESS 0x70
|
||||
|
||||
|
||||
// Create display and GPS objects. These are global variables that
|
||||
// can be accessed from both the setup and loop function below.
|
||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||
SoftwareSerial gpsSerial(8, 7); // GPS breakout/shield will use a
|
||||
// software serial connection with
|
||||
// TX = pin 8 and RX = pin 7.
|
||||
Adafruit_GPS gps(&gpsSerial);
|
||||
|
||||
|
||||
void setup() {
|
||||
// Setup function runs once at startup to initialize the display and GPS.
|
||||
|
||||
// Setup Serial port to print debug output.
|
||||
Serial.begin(115200);
|
||||
Serial.println("Clock starting!");
|
||||
|
||||
// Setup the display.
|
||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||
|
||||
// Setup the GPS using a 9600 baud connection (the default for most
|
||||
// GPS modules).
|
||||
gps.begin(9600);
|
||||
|
||||
// Configure GPS to onlu output minimum data (location, time, fix).
|
||||
gps.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
|
||||
|
||||
// Use a 1 hz, once a second, update rate.
|
||||
gps.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
|
||||
|
||||
// Enable the interrupt to parse GPS data.
|
||||
enableGPSInterrupt();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Loop function runs over and over again to implement the clock logic.
|
||||
|
||||
// Check if GPS has new data and parse it.
|
||||
if (gps.newNMEAreceived()) {
|
||||
gps.parse(gps.lastNMEA());
|
||||
}
|
||||
|
||||
// Grab the current hours, minutes, seconds from the GPS.
|
||||
// This will only be set once the GPS has a fix! Make sure to add
|
||||
// a coin cell battery so the GPS will save the time between power-up/down.
|
||||
int hours = gps.hour + HOUR_OFFSET; // Add hour offset to convert from UTC
|
||||
// to local time.
|
||||
// Handle when UTC + offset wraps around to a negative or > 23 value.
|
||||
if (hours < 0) {
|
||||
hours = 24+hours;
|
||||
}
|
||||
if (hours > 23) {
|
||||
hours = 24-hours;
|
||||
}
|
||||
int minutes = gps.minute;
|
||||
int seconds = gps.seconds;
|
||||
|
||||
// Show the time on the display by turning it into a numeric
|
||||
// value, like 3:30 turns into 330, by multiplying the hour by
|
||||
// 100 and then adding the minutes.
|
||||
int displayValue = hours*100 + minutes;
|
||||
|
||||
// Do 24 hour to 12 hour format conversion when required.
|
||||
if (!TIME_24_HOUR) {
|
||||
// Handle when hours are past 12 by subtracting 12 hours (1200 value).
|
||||
if (hours > 12) {
|
||||
displayValue -= 1200;
|
||||
}
|
||||
// Handle hour 0 (midnight) being shown as 12.
|
||||
else if (hours == 0) {
|
||||
displayValue += 1200;
|
||||
}
|
||||
}
|
||||
|
||||
// Now print the time value to the display.
|
||||
clockDisplay.print(displayValue, DEC);
|
||||
|
||||
// Add zero padding when in 24 hour mode and it's midnight.
|
||||
// In this case the print function above won't have leading 0's
|
||||
// which can look confusing. Go in and explicitly add these zeros.
|
||||
if (TIME_24_HOUR && hours == 0) {
|
||||
// Pad hour 0.
|
||||
clockDisplay.writeDigitNum(1, 0);
|
||||
// Also pad when the 10's minute is 0 and should be padded.
|
||||
if (minutes < 10) {
|
||||
clockDisplay.writeDigitNum(2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Blink the colon by turning it on every even second and off
|
||||
// every odd second. The modulus operator is very handy here to
|
||||
// check if a value is even (modulus 2 equals 0) or odd (modulus 2
|
||||
// equals 1).
|
||||
clockDisplay.drawColon(seconds % 2 == 0);
|
||||
|
||||
// Now push out to the display the new values that were set above.
|
||||
clockDisplay.writeDisplay();
|
||||
|
||||
// Loop code is finished, it will jump back to the start of the loop
|
||||
// function again! Don't add any delays because the parsing needs to
|
||||
// happen all the time!
|
||||
}
|
||||
|
||||
SIGNAL(TIMER0_COMPA_vect) {
|
||||
// Use a timer interrupt once a millisecond to check for new GPS data.
|
||||
// This piggybacks on Arduino's internal clock timer for the millis()
|
||||
// function.
|
||||
gps.read();
|
||||
}
|
||||
|
||||
void enableGPSInterrupt() {
|
||||
// Function to enable the timer interrupt that will parse GPS data.
|
||||
// Timer0 is already used for millis() - we'll just interrupt somewhere
|
||||
// in the middle and call the "Compare A" function above
|
||||
OCR0A = 0xAF;
|
||||
TIMSK0 |= _BV(OCIE0A);
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/***************************************************
|
||||
This is a library for our I2C LED Backpacks
|
||||
|
||||
Designed specifically to work with the Adafruit 16x8 LED Matrix backpacks
|
||||
----> http://www.adafruit.com/products/2035
|
||||
----> http://www.adafruit.com/products/2036
|
||||
----> http://www.adafruit.com/products/2037
|
||||
----> http://www.adafruit.com/products/2038
|
||||
----> http://www.adafruit.com/products/2039
|
||||
----> http://www.adafruit.com/products/2040
|
||||
----> http://www.adafruit.com/products/2041
|
||||
----> http://www.adafruit.com/products/2042
|
||||
----> http://www.adafruit.com/products/2043
|
||||
----> http://www.adafruit.com/products/2044
|
||||
----> http://www.adafruit.com/products/2052
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface. There are multiple selectable I2C addresses. For backpacks
|
||||
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
with 3 Address Select pins: 0x70 thru 0x77
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
Adafruit_8x16matrix matrix = Adafruit_8x16matrix();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("16x8 LED Matrix Test");
|
||||
|
||||
matrix.begin(0x70); // pass in the address
|
||||
}
|
||||
|
||||
static const uint8_t PROGMEM
|
||||
smile_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10100101,
|
||||
B10011001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
neutral_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10111101,
|
||||
B10000001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
frown_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10011001,
|
||||
B10100101,
|
||||
B01000010,
|
||||
B00111100 };
|
||||
|
||||
void loop() {
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 8, neutral_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear(); // clear display
|
||||
matrix.drawPixel(0, 0, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawLine(0,0, 7,15, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawRect(0,0, 8,16, LED_ON);
|
||||
matrix.fillRect(2,2, 4,12, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawCircle(3,8, 3, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.setTextSize(2);
|
||||
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
|
||||
matrix.setTextColor(LED_ON);
|
||||
for (int8_t x=0; x>=-64; x--) {
|
||||
matrix.clear();
|
||||
matrix.setCursor(x,0);
|
||||
matrix.print("Hello");
|
||||
matrix.writeDisplay();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
matrix.setTextSize(1);
|
||||
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
|
||||
matrix.setTextColor(LED_ON);
|
||||
matrix.setRotation(1);
|
||||
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,0 +1,120 @@
|
||||
/***************************************************
|
||||
This is a library for our I2C LED Backpacks
|
||||
|
||||
Designed specifically to work with the Adafruit LED Matrix backpacks
|
||||
----> http://www.adafruit.com/products/872
|
||||
----> http://www.adafruit.com/products/871
|
||||
----> http://www.adafruit.com/products/870
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface. There are multiple selectable I2C addresses. For backpacks
|
||||
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
with 3 Address Select pins: 0x70 thru 0x77
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("8x8 LED Matrix Test");
|
||||
|
||||
matrix.begin(0x70); // pass in the address
|
||||
}
|
||||
|
||||
static const uint8_t PROGMEM
|
||||
smile_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10100101,
|
||||
B10011001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
neutral_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10111101,
|
||||
B10000001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
frown_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10011001,
|
||||
B10100101,
|
||||
B01000010,
|
||||
B00111100 };
|
||||
|
||||
void loop() {
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, neutral_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear(); // clear display
|
||||
matrix.drawPixel(0, 0, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawLine(0,0, 7,7, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawRect(0,0, 8,8, LED_ON);
|
||||
matrix.fillRect(2,2, 4,4, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawCircle(3,3, 3, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
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>=-36; x--) {
|
||||
matrix.clear();
|
||||
matrix.setCursor(x,0);
|
||||
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,0 +1,123 @@
|
||||
/***************************************************
|
||||
This is a library for our I2C LED Backpacks & FeatherWings
|
||||
|
||||
Designed specifically to work with the Adafruit 16x8 LED Matrix FeatherWing
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface. There are multiple selectable I2C addresses. For backpacks
|
||||
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
with 3 Address Select pins: 0x70 thru 0x77
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
Adafruit_8x16minimatrix matrix = Adafruit_8x16minimatrix();
|
||||
|
||||
void setup() {
|
||||
//while (!Serial);
|
||||
Serial.begin(9600);
|
||||
Serial.println("16x8 LED Mini Matrix Test");
|
||||
|
||||
matrix.begin(0x70); // pass in the address
|
||||
}
|
||||
|
||||
static const uint8_t PROGMEM
|
||||
smile_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10100101,
|
||||
B10011001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
neutral_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10111101,
|
||||
B10000001,
|
||||
B01000010,
|
||||
B00111100 },
|
||||
frown_bmp[] =
|
||||
{ B00111100,
|
||||
B01000010,
|
||||
B10100101,
|
||||
B10000001,
|
||||
B10011001,
|
||||
B10100101,
|
||||
B01000010,
|
||||
B00111100 };
|
||||
|
||||
void loop() {
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 8, neutral_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_ON);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
|
||||
matrix.drawPixel(0, 0, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawLine(0,0, 7,15, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawRect(0,0, 8,16, LED_ON);
|
||||
matrix.fillRect(2,2, 4,12, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.clear();
|
||||
matrix.drawCircle(3,8, 3, LED_ON);
|
||||
matrix.writeDisplay(); // write the changes we just made to the display
|
||||
delay(500);
|
||||
|
||||
matrix.setTextSize(2);
|
||||
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
|
||||
matrix.setTextColor(LED_ON);
|
||||
for (int8_t x=0; x>=-64; x--) {
|
||||
matrix.clear();
|
||||
matrix.setCursor(x,0);
|
||||
matrix.print("Hello");
|
||||
matrix.writeDisplay();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
matrix.setTextSize(1);
|
||||
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
|
||||
matrix.setTextColor(LED_ON);
|
||||
matrix.setRotation(1);
|
||||
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,0 +1,73 @@
|
||||
// Demo the quad alphanumeric display LED backpack kit
|
||||
// scrolls through every character, then scrolls Serial
|
||||
// input onto the display
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
alpha4.begin(0x70); // pass in the address
|
||||
|
||||
alpha4.writeDigitRaw(3, 0x0);
|
||||
alpha4.writeDigitRaw(0, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
alpha4.writeDigitRaw(0, 0x0);
|
||||
alpha4.writeDigitRaw(1, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
alpha4.writeDigitRaw(1, 0x0);
|
||||
alpha4.writeDigitRaw(2, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
alpha4.writeDigitRaw(2, 0x0);
|
||||
alpha4.writeDigitRaw(3, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
|
||||
alpha4.clear();
|
||||
alpha4.writeDisplay();
|
||||
|
||||
// display every character,
|
||||
for (uint8_t i='!'; i<='z'; i++) {
|
||||
alpha4.writeDigitAscii(0, i);
|
||||
alpha4.writeDigitAscii(1, i+1);
|
||||
alpha4.writeDigitAscii(2, i+2);
|
||||
alpha4.writeDigitAscii(3, i+3);
|
||||
alpha4.writeDisplay();
|
||||
|
||||
delay(300);
|
||||
}
|
||||
Serial.println("Start typing to display!");
|
||||
}
|
||||
|
||||
|
||||
char displaybuffer[4] = {' ', ' ', ' ', ' '};
|
||||
|
||||
void loop() {
|
||||
while (! Serial.available()) return;
|
||||
|
||||
char c = Serial.read();
|
||||
if (! isprint(c)) return; // only printable!
|
||||
|
||||
// scroll down display
|
||||
displaybuffer[0] = displaybuffer[1];
|
||||
displaybuffer[1] = displaybuffer[2];
|
||||
displaybuffer[2] = displaybuffer[3];
|
||||
displaybuffer[3] = c;
|
||||
|
||||
// set every digit to the buffer
|
||||
alpha4.writeDigitAscii(0, displaybuffer[0]);
|
||||
alpha4.writeDigitAscii(1, displaybuffer[1]);
|
||||
alpha4.writeDigitAscii(2, displaybuffer[2]);
|
||||
alpha4.writeDigitAscii(3, displaybuffer[3]);
|
||||
|
||||
// write it out!
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// Demo the quad alphanumeric display LED backpack kit
|
||||
// Displays a short message and then scrolls through every character
|
||||
|
||||
// For use with Gemma or Trinket (Attiny85)
|
||||
|
||||
#include <avr/power.h>
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
// Connect + pins to 3-5V
|
||||
// Connect GND to ground
|
||||
// Connect Data to #0
|
||||
// Connect Clock to #2
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
char *message = "Hello world! ";
|
||||
|
||||
Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
|
||||
|
||||
void setup() {
|
||||
// This is the auto-speed doubler line, keep it in, it will
|
||||
// automatically double the speed when 16Mhz is selected!
|
||||
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
|
||||
|
||||
alpha4.begin(0x70); // pass in the address
|
||||
|
||||
alpha4.writeDigitRaw(3, 0x0);
|
||||
alpha4.writeDigitRaw(0, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
alpha4.writeDigitRaw(0, 0x0);
|
||||
alpha4.writeDigitRaw(1, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
alpha4.writeDigitRaw(1, 0x0);
|
||||
alpha4.writeDigitRaw(2, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
alpha4.writeDigitRaw(2, 0x0);
|
||||
alpha4.writeDigitRaw(3, 0xFFFF);
|
||||
alpha4.writeDisplay();
|
||||
delay(200);
|
||||
|
||||
alpha4.clear();
|
||||
alpha4.writeDisplay();
|
||||
|
||||
// send a message!
|
||||
for (uint8_t i=0; i<strlen(message)-4; i++) {
|
||||
alpha4.writeDigitAscii(0, message[i]);
|
||||
alpha4.writeDigitAscii(1, message[i+1]);
|
||||
alpha4.writeDigitAscii(2, message[i+2]);
|
||||
alpha4.writeDigitAscii(3, message[i+3]);
|
||||
alpha4.writeDisplay();
|
||||
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// display every character,
|
||||
for (uint8_t i='!'; i<='z'; i++) {
|
||||
alpha4.writeDigitAscii(0, i);
|
||||
alpha4.writeDigitAscii(1, i+1);
|
||||
alpha4.writeDigitAscii(2, i+2);
|
||||
alpha4.writeDigitAscii(3, i+3);
|
||||
alpha4.writeDisplay();
|
||||
|
||||
delay(300);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
// 'roboface' example sketch for Adafruit I2C 8x8 LED backpacks:
|
||||
//
|
||||
// www.adafruit.com/products/870 www.adafruit.com/products/1049
|
||||
// www.adafruit.com/products/871 www.adafruit.com/products/1050
|
||||
// www.adafruit.com/products/872 www.adafruit.com/products/1051
|
||||
// www.adafruit.com/products/959 www.adafruit.com/products/1052
|
||||
//
|
||||
// Requires Adafruit_LEDBackpack and Adafruit_GFX libraries.
|
||||
// For a simpler introduction, see the 'matrix8x8' example.
|
||||
//
|
||||
// This sketch demonstrates a couple of useful techniques:
|
||||
// 1) Addressing multiple matrices (using the 'A0' and 'A1' solder
|
||||
// pads on the back to select unique I2C addresses for each).
|
||||
// 2) Displaying the same data on multiple matrices by sharing the
|
||||
// same I2C address.
|
||||
//
|
||||
// This example uses 5 matrices at 4 addresses (two share an address)
|
||||
// to animate a face:
|
||||
//
|
||||
// 0 0
|
||||
//
|
||||
// 1 2 3
|
||||
//
|
||||
// The 'eyes' both display the same image (always looking the same
|
||||
// direction -- can't go cross-eyed) and thus share the same address
|
||||
// (0x70). The three matrices forming the mouth have unique addresses
|
||||
// (0x71, 0x72 and 0x73).
|
||||
//
|
||||
// The face animation as written is here semi-random; this neither
|
||||
// generates nor responds to actual sound, it's simply a visual effect
|
||||
// Consider this a stepping off point for your own project. Maybe you
|
||||
// could 'puppet' the face using joysticks, or synchronize the lips to
|
||||
// audio from a Wave Shield (see wavface example). Currently there are
|
||||
// only six images for the mouth. This is often sufficient for simple
|
||||
// animation, as explained here:
|
||||
// http://www.idleworm.com/how/anm/03t/talk1.shtml
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code,
|
||||
// please support Adafruit and open-source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by P. Burgess for Adafruit Industries.
|
||||
// BSD license, all text above must be included in any redistribution.
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
// Because the two eye matrices share the same address, only four
|
||||
// matrix objects are needed for the five displays:
|
||||
#define MATRIX_EYES 0
|
||||
#define MATRIX_MOUTH_LEFT 1
|
||||
#define MATRIX_MOUTH_MIDDLE 2
|
||||
#define MATRIX_MOUTH_RIGHT 3
|
||||
Adafruit_8x8matrix matrix[4] = { // Array of Adafruit_8x8matrix objects
|
||||
Adafruit_8x8matrix(), Adafruit_8x8matrix(),
|
||||
Adafruit_8x8matrix(), Adafruit_8x8matrix() };
|
||||
|
||||
// Rather than assigning matrix addresses sequentially in a loop, each
|
||||
// has a spot in this array. This makes it easier if you inadvertently
|
||||
// install one or more matrices in the wrong physical position --
|
||||
// re-order the addresses in this table and you can still refer to
|
||||
// matrices by index above, no other code or wiring needs to change.
|
||||
static const uint8_t matrixAddr[] = { 0x70, 0x71, 0x72, 0x73 };
|
||||
|
||||
static const uint8_t PROGMEM // Bitmaps are stored in program memory
|
||||
blinkImg[][8] = { // Eye animation frames
|
||||
{ B00111100, // Fully open eye
|
||||
B01111110,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B01111110,
|
||||
B00111100 },
|
||||
{ B00000000,
|
||||
B01111110,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B01111110,
|
||||
B00111100 },
|
||||
{ B00000000,
|
||||
B00000000,
|
||||
B00111100,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B00111100,
|
||||
B00000000 },
|
||||
{ B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00111100,
|
||||
B11111111,
|
||||
B01111110,
|
||||
B00011000,
|
||||
B00000000 },
|
||||
{ B00000000, // Fully closed eye
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B10000001,
|
||||
B01111110,
|
||||
B00000000,
|
||||
B00000000 } },
|
||||
mouthImg[][24] = { // Mouth animation frames
|
||||
{ B00000000, B00000000, B00000000, // Mouth position A
|
||||
B00000000, B00000000, B00000000,
|
||||
B01111111, B11111111, B11111110,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position B
|
||||
B00000000, B00000000, B00000000,
|
||||
B00111111, B11111111, B11111100,
|
||||
B00000111, B00000000, B11100000,
|
||||
B00000000, B11111111, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position C
|
||||
B00000000, B00000000, B00000000,
|
||||
B00111111, B11111111, B11111100,
|
||||
B00001000, B00000000, B00010000,
|
||||
B00000110, B00000000, B01100000,
|
||||
B00000001, B11000011, B10000000,
|
||||
B00000000, B00111100, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position D
|
||||
B00000000, B00000000, B00000000,
|
||||
B00111111, B11111111, B11111100,
|
||||
B00100000, B00000000, B00000100,
|
||||
B00010000, B00000000, B00001000,
|
||||
B00001100, B00000000, B00110000,
|
||||
B00000011, B10000001, B11000000,
|
||||
B00000000, B01111110, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position E
|
||||
B00000000, B00111100, B00000000,
|
||||
B00011111, B11000011, B11111000,
|
||||
B00000011, B10000001, B11000000,
|
||||
B00000000, B01111110, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00111100, B00000000, // Mouth position F
|
||||
B00000000, B11000011, B00000000,
|
||||
B00001111, B00000000, B11110000,
|
||||
B00000001, B00000000, B10000000,
|
||||
B00000000, B11000011, B00000000,
|
||||
B00000000, B00111100, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 } };
|
||||
|
||||
uint8_t
|
||||
blinkIndex[] = { 1, 2, 3, 4, 3, 2, 1 }, // Blink bitmap sequence
|
||||
blinkCountdown = 100, // Countdown to next blink (in frames)
|
||||
gazeCountdown = 75, // Countdown to next eye movement
|
||||
gazeFrames = 50, // Duration of eye movement (smaller = faster)
|
||||
mouthPos = 0, // Current image number for mouth
|
||||
mouthCountdown = 10; // Countdown to next mouth change
|
||||
int8_t
|
||||
eyeX = 3, eyeY = 3, // Current eye position
|
||||
newX = 3, newY = 3, // Next eye position
|
||||
dX = 0, dY = 0; // Distance from prior to new position
|
||||
|
||||
void setup() {
|
||||
|
||||
// Seed random number generator from an unused analog input:
|
||||
randomSeed(analogRead(A0));
|
||||
|
||||
// Initialize each matrix object:
|
||||
for(uint8_t i=0; i<4; i++) {
|
||||
matrix[i].begin(matrixAddr[i]);
|
||||
// If using 'small' (1.2") displays vs. 'mini' (0.8"), enable this:
|
||||
// matrix[i].setRotation(3);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Draw eyeball in current state of blinkyness (no pupil). Note that
|
||||
// only one eye needs to be drawn. Because the two eye matrices share
|
||||
// the same address, the same data will be received by both.
|
||||
matrix[MATRIX_EYES].clear();
|
||||
// When counting down to the next blink, show the eye in the fully-
|
||||
// open state. On the last few counts (during the blink), look up
|
||||
// the corresponding bitmap index.
|
||||
matrix[MATRIX_EYES].drawBitmap(0, 0,
|
||||
blinkImg[
|
||||
(blinkCountdown < sizeof(blinkIndex)) ? // Currently blinking?
|
||||
blinkIndex[blinkCountdown] : // Yes, look up bitmap #
|
||||
0 // No, show bitmap 0
|
||||
], 8, 8, LED_ON);
|
||||
// Decrement blink counter. At end, set random time for next blink.
|
||||
if(--blinkCountdown == 0) blinkCountdown = random(5, 180);
|
||||
|
||||
// Add a pupil (2x2 black square) atop the blinky eyeball bitmap.
|
||||
// Periodically, the pupil moves to a new position...
|
||||
if(--gazeCountdown <= gazeFrames) {
|
||||
// Eyes are in motion - draw pupil at interim position
|
||||
matrix[MATRIX_EYES].fillRect(
|
||||
newX - (dX * gazeCountdown / gazeFrames),
|
||||
newY - (dY * gazeCountdown / gazeFrames),
|
||||
2, 2, LED_OFF);
|
||||
if(gazeCountdown == 0) { // Last frame?
|
||||
eyeX = newX; eyeY = newY; // Yes. What's new is old, then...
|
||||
do { // Pick random positions until one is within the eye circle
|
||||
newX = random(7); newY = random(7);
|
||||
dX = newX - 3; dY = newY - 3;
|
||||
} while((dX * dX + dY * dY) >= 10); // Thank you Pythagoras
|
||||
dX = newX - eyeX; // Horizontal distance to move
|
||||
dY = newY - eyeY; // Vertical distance to move
|
||||
gazeFrames = random(3, 15); // Duration of eye movement
|
||||
gazeCountdown = random(gazeFrames, 120); // Count to end of next movement
|
||||
}
|
||||
} else {
|
||||
// Not in motion yet -- draw pupil at current static position
|
||||
matrix[MATRIX_EYES].fillRect(eyeX, eyeY, 2, 2, LED_OFF);
|
||||
}
|
||||
|
||||
// Draw mouth, switch to new random image periodically
|
||||
drawMouth(mouthImg[mouthPos]);
|
||||
if(--mouthCountdown == 0) {
|
||||
mouthPos = random(6); // Random image
|
||||
// If the 'neutral' position was chosen, there's a 1-in-5 chance we'll
|
||||
// select a longer hold time. This gives the appearance of periodic
|
||||
// pauses in speech (e.g. between sentences, etc.).
|
||||
mouthCountdown = ((mouthPos == 0) && (random(5) == 0)) ?
|
||||
random(10, 40) : // Longer random duration
|
||||
random(2, 8); // Shorter random duration
|
||||
}
|
||||
|
||||
// Refresh all of the matrices in one quick pass
|
||||
for(uint8_t i=0; i<4; i++) matrix[i].writeDisplay();
|
||||
|
||||
delay(20); // ~50 FPS
|
||||
}
|
||||
|
||||
// Draw mouth image across three adjacent displays
|
||||
void drawMouth(const uint8_t *img) {
|
||||
for(uint8_t i=0; i<3; i++) {
|
||||
matrix[MATRIX_MOUTH_LEFT + i].clear();
|
||||
matrix[MATRIX_MOUTH_LEFT + i].drawBitmap(i * -8, 0, img, 24, 8, LED_ON);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/***************************************************
|
||||
This is a library for our I2C LED Backpacks
|
||||
|
||||
Designed specifically to work with the Adafruit LED 7-Segment backpacks
|
||||
----> http://www.adafruit.com/products/881
|
||||
----> http://www.adafruit.com/products/880
|
||||
----> http://www.adafruit.com/products/879
|
||||
----> http://www.adafruit.com/products/878
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface. There are multiple selectable I2C addresses. For backpacks
|
||||
with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
|
||||
with 3 Address Select pins: 0x70 thru 0x77
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
Adafruit_7segment matrix = Adafruit_7segment();
|
||||
|
||||
void setup() {
|
||||
#ifndef __AVR_ATtiny85__
|
||||
Serial.begin(9600);
|
||||
Serial.println("7 Segment Backpack Test");
|
||||
#endif
|
||||
matrix.begin(0x70);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// try to print a number thats too long
|
||||
matrix.print(10000, DEC);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
// print a hex number
|
||||
matrix.print(0xBEEF, HEX);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
// print a floating point
|
||||
matrix.print(12.34);
|
||||
matrix.writeDisplay();
|
||||
delay(500);
|
||||
|
||||
// print with print/println
|
||||
for (uint16_t counter = 0; counter < 9999; counter++) {
|
||||
matrix.println(counter);
|
||||
matrix.writeDisplay();
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// method #2 - draw each digit
|
||||
uint16_t blinkcounter = 0;
|
||||
boolean drawDots = false;
|
||||
for (uint16_t counter = 0; counter < 9999; counter ++) {
|
||||
matrix.writeDigitNum(0, (counter / 1000), drawDots);
|
||||
matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);
|
||||
matrix.drawColon(drawDots);
|
||||
matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);
|
||||
matrix.writeDigitNum(4, counter % 10, drawDots);
|
||||
|
||||
blinkcounter+=50;
|
||||
if (blinkcounter < 500) {
|
||||
drawDots = false;
|
||||
} else if (blinkcounter < 1000) {
|
||||
drawDots = true;
|
||||
} else {
|
||||
blinkcounter = 0;
|
||||
}
|
||||
matrix.writeDisplay();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
// 'wavface' example sketch for Adafruit I2C 8x8 LED backpacks
|
||||
// and Wave Shield:
|
||||
//
|
||||
// www.adafruit.com/products/870 www.adafruit.com/products/1049
|
||||
// www.adafruit.com/products/871 www.adafruit.com/products/1050
|
||||
// www.adafruit.com/products/872 www.adafruit.com/products/1051
|
||||
// www.adafruit.com/products/959 www.adafruit.com/products/1052
|
||||
// www.adafruit.com/products/94
|
||||
//
|
||||
// Requires Adafruit_LEDBackpack, Adafruit_GFX libraries and WaveHC
|
||||
// libraries.
|
||||
//
|
||||
// This sketch shows animation roughly synchronized to prerecorded
|
||||
// speech. It's fairly complex and may be overwhelming to novice
|
||||
// programmers, who may want to start with the 'matrix8x8' example
|
||||
// and then 'roboface' before working through this code. Also, much
|
||||
// of the comments relating to the face animation have been stripped
|
||||
// here for brevity...refer to the 'roboface' sketch if you have any
|
||||
// questions how that part works.
|
||||
//
|
||||
// Additional hardware required: sounds are triggered using three
|
||||
// normally-open momentary buttons connected to Digital pins 6, 7, 8
|
||||
// and GND. (e.g. www.adafruit.com/products/1009 )
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code,
|
||||
// please support Adafruit and open-source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by P. Burgess for Adafruit Industries, parts adapted from
|
||||
// 'PiSpeakHC' sketch included with WaveHC library.
|
||||
// BSD license, all text above must be included in any redistribution.
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <WaveHC.h>
|
||||
#include <WaveUtil.h>
|
||||
#include "Adafruit_LEDBackpack.h"
|
||||
|
||||
// These WAV files should be in the root level of the SD card:
|
||||
static const char PROGMEM
|
||||
wav0[] = "beware_i.wav",
|
||||
wav1[] = "ihunger.wav",
|
||||
wav2[] = "run_cowd.wav";
|
||||
static const char * const wavname[] PROGMEM = { wav0, wav1, wav2 };
|
||||
// PROGMEM makes frequent appearances throughout this code, reason being that
|
||||
// the SD card library requires gobs of precious RAM (leaving very little to
|
||||
// our own sketch). PROGMEM lets us put fixed data into program flash memory,
|
||||
// which is considerably more spacious. String tables are paritcularly nasty.
|
||||
// See www.arduino.cc/en/Reference/PROGMEM for more info.
|
||||
|
||||
SdReader card; // This object holds the information for the card
|
||||
FatVolume vol; // This holds the information for the partition on the card
|
||||
FatReader root; // This holds the information for the volumes root directory
|
||||
FatReader file; // This object represent the WAV file for a phrase
|
||||
WaveHC wave; // A single wave object -- only one sound is played at a time
|
||||
|
||||
// Because the two eye matrices share the same address, only four
|
||||
// matrix objects are needed for the five displays:
|
||||
#define MATRIX_EYES 0
|
||||
#define MATRIX_MOUTH_LEFT 1
|
||||
#define MATRIX_MOUTH_MIDDLE 2
|
||||
#define MATRIX_MOUTH_RIGHT 3
|
||||
Adafruit_8x8matrix matrix[4] = { // Array of Adafruit_8x8matrix objects
|
||||
Adafruit_8x8matrix(), Adafruit_8x8matrix(),
|
||||
Adafruit_8x8matrix(), Adafruit_8x8matrix() };
|
||||
|
||||
// Rather than assigning matrix addresses sequentially in a loop, each
|
||||
// has a spot in this array. This makes it easier if you inadvertently
|
||||
// install one or more matrices in the wrong physical position --
|
||||
// re-order the addresses in this table and you can still refer to
|
||||
// matrices by index above, no other code or wiring needs to change.
|
||||
static const uint8_t PROGMEM matrixAddr[] = { 0x70, 0x71, 0x72, 0x73 };
|
||||
|
||||
static const uint8_t PROGMEM // Bitmaps are stored in program memory
|
||||
blinkImg[][8] = { // Eye animation frames
|
||||
{ B00111100, // Fully open eye
|
||||
B01111110,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B01111110,
|
||||
B00111100 },
|
||||
{ B00000000,
|
||||
B01111110,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B01111110,
|
||||
B00111100 },
|
||||
{ B00000000,
|
||||
B00000000,
|
||||
B00111100,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B11111111,
|
||||
B00111100,
|
||||
B00000000 },
|
||||
{ B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00111100,
|
||||
B11111111,
|
||||
B01111110,
|
||||
B00011000,
|
||||
B00000000 },
|
||||
{ B00000000, // Fully closed eye
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B10000001,
|
||||
B01111110,
|
||||
B00000000,
|
||||
B00000000 } },
|
||||
mouthImg[][24] = { // Mouth animation frames
|
||||
{ B00000000, B00000000, B00000000, // Mouth position A
|
||||
B00000000, B00000000, B00000000,
|
||||
B01111111, B11111111, B11111110,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position B
|
||||
B00000000, B00000000, B00000000,
|
||||
B00111111, B11111111, B11111100,
|
||||
B00000111, B00000000, B11100000,
|
||||
B00000000, B11111111, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position C
|
||||
B00000000, B00000000, B00000000,
|
||||
B00111111, B11111111, B11111100,
|
||||
B00001000, B00000000, B00010000,
|
||||
B00000110, B00000000, B01100000,
|
||||
B00000001, B11000011, B10000000,
|
||||
B00000000, B00111100, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position D
|
||||
B00000000, B00000000, B00000000,
|
||||
B00111111, B11111111, B11111100,
|
||||
B00100000, B00000000, B00000100,
|
||||
B00010000, B00000000, B00001000,
|
||||
B00001100, B00000000, B00110000,
|
||||
B00000011, B10000001, B11000000,
|
||||
B00000000, B01111110, B00000000 },
|
||||
{ B00000000, B00000000, B00000000, // Mouth position E
|
||||
B00000000, B00111100, B00000000,
|
||||
B00011111, B11000011, B11111000,
|
||||
B00000011, B10000001, B11000000,
|
||||
B00000000, B01111110, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 },
|
||||
{ B00000000, B00111100, B00000000, // Mouth position F
|
||||
B00000000, B11000011, B00000000,
|
||||
B00001111, B00000000, B11110000,
|
||||
B00000001, B00000000, B10000000,
|
||||
B00000000, B11000011, B00000000,
|
||||
B00000000, B00111100, B00000000,
|
||||
B00000000, B00000000, B00000000,
|
||||
B00000000, B00000000, B00000000 } };
|
||||
|
||||
// Animation sequences corresponding to each WAV. First number in
|
||||
// each pair is a mouth bitmap index. Second number is the hold
|
||||
// time (in frames). 255 marks end of list.
|
||||
// There is no 'magic' here, the software is NOT deriving mouth
|
||||
// position from the sound...the tables were determined by hand,
|
||||
// just as animators do it. Further explanation here:
|
||||
// http://www.idleworm.com/how/anm/03t/talk1.shtml
|
||||
|
||||
static const uint8_t PROGMEM
|
||||
seq1[] = { 0, 2, 2, 5, 5, 3, 3, 7, // "Beware, I live!"
|
||||
4, 5, 3, 4, 2, 5, 4, 3,
|
||||
3, 4, 1, 5, 3, 5, 255 },
|
||||
seq2[] = { 0, 1, 3, 5, 1, 5, 4, 2, // "I hunger!"
|
||||
3, 2, 1, 2, 4, 4, 1, 3,
|
||||
4, 2, 255 },
|
||||
seq3[] = { 0, 1, 1, 2, 3, 6, 2, 5, // "Run, coward!"
|
||||
0, 1, 4, 4, 5, 2, 1, 5,
|
||||
3, 6, 1, 4, 255 };
|
||||
static const uint8_t * const anim[] = { seq1, seq2, seq3 };
|
||||
|
||||
const uint8_t
|
||||
blinkIndex[] PROGMEM = { 1, 2, 3, 4, 3, 2, 1 }; // Blink bitmap sequence
|
||||
uint8_t
|
||||
blinkCountdown = 100, // Countdown to next blink (in frames)
|
||||
gazeCountdown = 75, // Countdown to next eye movement
|
||||
gazeFrames = 50, // Duration of eye movement (smaller = faster)
|
||||
mouthPos = 0, // Current image number for mouth
|
||||
mouthCountdown = 10, // Countdown to next mouth change
|
||||
newPos = 255, // New mouth position for current frame
|
||||
*seq, // Animation sequence currently being played back
|
||||
idx, // Current array index within animation sequence
|
||||
prevBtn = 99, // Button # pressed on last loop() iteration
|
||||
btnCount = 0; // Number of iterations same button has been held
|
||||
int8_t
|
||||
eyeX = 3, eyeY = 3, // Current eye position
|
||||
newX = 3, newY = 3, // Next eye position
|
||||
dX = 0, dY = 0; // Distance from prior to new position
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println(F("WAV face"));
|
||||
|
||||
if(!card.init()) Serial.println(F("Card init. failed!"));
|
||||
if(!vol.init(card)) Serial.println(F("No partition!"));
|
||||
if(!root.openRoot(vol)) Serial.println(F("Couldn't open dir"));
|
||||
Serial.println(F("Files found:"));
|
||||
root.ls();
|
||||
|
||||
// Seed random number generator from an unused analog input:
|
||||
randomSeed(analogRead(A0));
|
||||
|
||||
// Initialize each matrix object:
|
||||
for(uint8_t i=0; i<4; i++) {
|
||||
matrix[i].begin(pgm_read_byte(&matrixAddr[i]));
|
||||
// If using 'small' (1.2") displays vs. 'mini' (0.8"), enable this:
|
||||
// matrix[i].setRotation(3);
|
||||
}
|
||||
|
||||
// Enable pull-up resistors on three button inputs.
|
||||
// Other end of each button then connects to GND.
|
||||
for(uint8_t i=6; i<=8; i++) {
|
||||
pinMode(i, INPUT);
|
||||
digitalWrite(i, HIGH); // Enable pullup
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
uint8_t i;
|
||||
|
||||
// Draw eyeball in current state of blinkyness (no pupil).
|
||||
matrix[MATRIX_EYES].clear();
|
||||
matrix[MATRIX_EYES].drawBitmap(0, 0,
|
||||
blinkImg[
|
||||
(blinkCountdown < sizeof(blinkIndex)) ? // Currently blinking?
|
||||
pgm_read_byte(&blinkIndex[blinkCountdown]) : // Yes, look up bitmap #
|
||||
0 // No, show bitmap 0
|
||||
], 8, 8, LED_ON);
|
||||
// Decrement blink counter. At end, set random time for next blink.
|
||||
if(--blinkCountdown == 0) blinkCountdown = random(5, 180);
|
||||
|
||||
if(--gazeCountdown <= gazeFrames) {
|
||||
// Eyes are in motion - draw pupil at interim position
|
||||
matrix[MATRIX_EYES].fillRect(
|
||||
newX - (dX * gazeCountdown / gazeFrames),
|
||||
newY - (dY * gazeCountdown / gazeFrames),
|
||||
2, 2, LED_OFF);
|
||||
if(gazeCountdown == 0) { // Last frame?
|
||||
eyeX = newX; eyeY = newY; // Yes. What's new is old, then...
|
||||
do { // Pick random positions until one is within the eye circle
|
||||
newX = random(7); newY = random(7);
|
||||
dX = newX - 3; dY = newY - 3;
|
||||
} while((dX * dX + dY * dY) >= 10); // Thank you Pythagoras
|
||||
dX = newX - eyeX; // Horizontal distance to move
|
||||
dY = newY - eyeY; // Vertical distance to move
|
||||
gazeFrames = random(3, 15); // Duration of eye movement
|
||||
gazeCountdown = random(gazeFrames, 120); // Count to end of next movement
|
||||
}
|
||||
} else {
|
||||
// Not in motion yet -- draw pupil at current static position
|
||||
matrix[MATRIX_EYES].fillRect(eyeX, eyeY, 2, 2, LED_OFF);
|
||||
}
|
||||
|
||||
// Scan buttons 6, 7, 8 looking for first button pressed...
|
||||
for(i=0; (i<3) && (digitalRead(i+6) == HIGH); i++);
|
||||
|
||||
if(i < 3) { // Anything pressed? Yes!
|
||||
if(i == prevBtn) { // Same as last time we checked? Good!
|
||||
if(++btnCount == 3) { // 3 passes to 'debounce' button input
|
||||
playfile((char *)pgm_read_word(&wavname[i])); // Start WAV
|
||||
// Look up animation sequence # corresponding to this WAV...
|
||||
seq = (uint8_t *)pgm_read_word(&anim[i]);
|
||||
idx = 0; // Begin at first byte of data
|
||||
newPos = pgm_read_byte(&seq[idx++]); // Initial mouth pos
|
||||
mouthCountdown = pgm_read_byte(&seq[idx++]); // Hold time for pos
|
||||
}
|
||||
} else btnCount = 0; // Different button than before - start count over
|
||||
prevBtn = i;
|
||||
} else prevBtn = 99; // No buttons pressed
|
||||
|
||||
if(newPos != 255) { // Is the mouth in motion?
|
||||
if(--mouthCountdown == 0) { // Count down frames to next position
|
||||
newPos = pgm_read_byte(&seq[idx++]); // New mouth position
|
||||
if(newPos == 255) { // End of list?
|
||||
mouthPos = 0; // Yes, set mouth to neutral position
|
||||
} else {
|
||||
mouthPos = newPos; // Set mouth to new position
|
||||
mouthCountdown = pgm_read_byte(&seq[idx++]); // Read hold time
|
||||
}
|
||||
}
|
||||
} else mouthPos = 0; // Mouth not in motion -- set to neutral position
|
||||
|
||||
drawMouth(mouthImg[mouthPos]);
|
||||
|
||||
// Refresh all matrices in one quick pass
|
||||
for(uint8_t i=0; i<4; i++) matrix[i].writeDisplay();
|
||||
|
||||
delay(20);
|
||||
}
|
||||
|
||||
// Draw mouth image across three adjacent displays
|
||||
void drawMouth(const uint8_t *img) {
|
||||
for(uint8_t i=0; i<3; i++) {
|
||||
matrix[MATRIX_MOUTH_LEFT + i].clear();
|
||||
matrix[MATRIX_MOUTH_LEFT + i].drawBitmap(i * -8, 0, img, 24, 8, LED_ON);
|
||||
}
|
||||
}
|
||||
|
||||
// Open and start playing a WAV file
|
||||
void playfile(const char *name) {
|
||||
char filename[13]; // 8.3+NUL
|
||||
|
||||
if(wave.isplaying) wave.stop(); // Stop any currently-playing WAV
|
||||
|
||||
strcpy_P(filename, name); // Copy name out of PROGMEM into RAM
|
||||
|
||||
if(!file.open(root, filename)) {
|
||||
Serial.print(F("Couldn't open file "));
|
||||
Serial.println(filename);
|
||||
return;
|
||||
}
|
||||
if(!wave.create(file)) {
|
||||
Serial.println(F("Not a valid WAV"));
|
||||
return;
|
||||
}
|
||||
wave.play();
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,10 @@
|
||||
name=Adafruit LED Backpack Library
|
||||
version=1.1.9
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Adafruit LED Backpack Library for our 8x8 matrix and 7-segment LED backpacks
|
||||
paragraph=Adafruit LED Backpack Library for our 8x8 matrix and 7-segment LED backpacks
|
||||
category=Display
|
||||
url=https://github.com/adafruit/Adafruit-LED-Backpack-Library
|
||||
depends=Adafruit GFX Library, WaveHC, RTClib, Adafruit GPS Library
|
||||
architectures=*
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Adafruit Industries
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
Reference in New Issue
Block a user