For 24bar graph support

Dependents:   toastboard_integrated

Fork of Adafruit_LEDBackpack_2 by Daniel Drew

Revision:
2:0491b3f9a639
Parent:
1:f066d5347c60
--- 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);
+  } 
+}