For 24bar graph support
Dependents: toastboard_integrated
Fork of Adafruit_LEDBackpack_2 by
Revision 2:0491b3f9a639, committed 2014-11-18
- Comitter:
- ddrew73
- Date:
- Tue Nov 18 01:19:49 2014 +0000
- Parent:
- 1:f066d5347c60
- Commit message:
- Edited to include the Adafruit 24 bicolor bargraph functionality.
Changed in this revision
Adafruit_LEDBackpack.cpp | Show annotated file Show diff for this revision Revisions of this file |
Adafruit_LEDBackpack.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r f066d5347c60 -r 0491b3f9a639 Adafruit_LEDBackpack.cpp --- a/Adafruit_LEDBackpack.cpp Fri Aug 16 15:44:44 2013 +0000 +++ b/Adafruit_LEDBackpack.cpp Tue Nov 18 01:19:49 2014 +0000 @@ -21,11 +21,19 @@ /* * Modified by Luiz Hespanha (http://www.d3.do) 8/16/2013 for use in LPC1768 */ + + /* + * Modified by Daniel Drew 11/13/2014 for use with 24ledbar backpack + */ #include "mbed.h" #include "Adafruit_LEDBackpack.h" #include "Adafruit_GFX.h" +#ifndef _BV + #define _BV(bit) (1<<(bit)) +#endif + void Adafruit_LEDBackpack::setBrightness(uint8_t b) { if (b > 15) b = 15; uint8_t c = 0xE0 | b; @@ -111,4 +119,42 @@ } else { displaybuffer[y] &= ~(1 << x); } -} \ No newline at end of file +} + + +/******************************* 24 BARGRAPH OBJECT */ + +Adafruit_24bargraph::Adafruit_24bargraph(I2C *i2c): Adafruit_LEDBackpack(i2c) { +} + +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); + } +}
diff -r f066d5347c60 -r 0491b3f9a639 Adafruit_LEDBackpack.h --- a/Adafruit_LEDBackpack.h Fri Aug 16 15:44:44 2013 +0000 +++ b/Adafruit_LEDBackpack.h Tue Nov 18 01:19:49 2014 +0000 @@ -22,6 +22,10 @@ * Modified by Luiz Hespanha (http://www.d3.do) 8/16/2013 for use in LPC1768 */ +/* + * Modified by Daniel Drew 11/13/2014 for use with 24ledbar backpack + */ + #include "mbed.h" #include "Adafruit_GFX.h" @@ -33,7 +37,6 @@ #define LED_GREEN 3 - #define HT16K33_BLINK_CMD 0x80 #define HT16K33_BLINK_DISPLAYON 0x01 #define HT16K33_BLINK_OFF 0 @@ -71,4 +74,13 @@ void drawPixel(int16_t x, int16_t y, uint16_t color); private: -}; \ No newline at end of file +}; + +class Adafruit_24bargraph : public Adafruit_LEDBackpack { + public: + Adafruit_24bargraph(I2C *i2c); + + void setBar(uint8_t bar, uint8_t color); + + private: +};