the rest of the commit
[the_perfect_clock.git] / display_test / display_test.ino
diff --git a/display_test/display_test.ino b/display_test/display_test.ino
new file mode 100755 (executable)
index 0000000..3a585b9
--- /dev/null
@@ -0,0 +1,88 @@
+#include <Adafruit_LEDBackpack.h>\r
+\r
+#include <Adafruit_GFX.h>\r
+#include <Adafruit_SPITFT.h>\r
+#include <Adafruit_SPITFT_Macros.h>\r
+#include <gfxfont.h>\r
+\r
+/*************************************************** \r
+  This is a library for our I2C LED Backpacks\r
+\r
+  Designed specifically to work with the Adafruit LED 7-Segment backpacks \r
+  ----> http://www.adafruit.com/products/881\r
+  ----> http://www.adafruit.com/products/880\r
+  ----> http://www.adafruit.com/products/879\r
+  ----> http://www.adafruit.com/products/878\r
+\r
+  These displays use I2C to communicate, 2 pins are required to \r
+  interface. There are multiple selectable I2C addresses. For backpacks\r
+  with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks\r
+  with 3 Address Select pins: 0x70 thru 0x77\r
+\r
+  Adafruit invests time and resources providing this open source code, \r
+  please support Adafruit and open-source hardware by purchasing \r
+  products from Adafruit!\r
+\r
+  Written by Limor Fried/Ladyada for Adafruit Industries.  \r
+  BSD license, all text above must be included in any redistribution\r
+ ****************************************************/\r
+\r
+//#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.\r
+#include <Adafruit_GFX.h>\r
+#include "Adafruit_LEDBackpack.h"\r
+\r
+Adafruit_7segment matrix = Adafruit_7segment();\r
+\r
+void setup() {\r
+#ifndef __AVR_ATtiny85__\r
+  Serial.begin(9600);\r
+  Serial.println("7 Segment Backpack Test");\r
+#endif\r
+  matrix.begin(0x70);\r
+}\r
+\r
+void loop() {\r
+  // try to print a number thats too long\r
+  matrix.print(10000, DEC);\r
+  matrix.writeDisplay();\r
+  delay(500);\r
+\r
+  // print a hex number\r
+  matrix.print(0xBEEF, HEX);\r
+  matrix.writeDisplay();\r
+  delay(500);\r
+\r
+  // print a floating point \r
+  matrix.print(12.34);\r
+  matrix.writeDisplay();\r
+  delay(500);\r
+  \r
+  // print with print/println\r
+  for (uint16_t counter = 0; counter < 9999; counter++) {\r
+    matrix.println(counter);\r
+    matrix.writeDisplay();\r
+    delay(10);\r
+  }\r
+\r
+  // method #2 - draw each digit\r
+  uint16_t blinkcounter = 0;\r
+  boolean drawDots = false;\r
+  for (uint16_t counter = 0; counter < 9999; counter ++) {\r
+    matrix.writeDigitNum(0, (counter / 1000), drawDots);\r
+    matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);\r
+    matrix.drawColon(drawDots);\r
+    matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);\r
+    matrix.writeDigitNum(4, counter % 10, drawDots);\r
+   \r
+    blinkcounter+=50;\r
+    if (blinkcounter < 500) {\r
+      drawDots = false;\r
+    } else if (blinkcounter < 1000) {\r
+      drawDots = true;\r
+    } else {\r
+      blinkcounter = 0;\r
+    }\r
+    matrix.writeDisplay();\r
+    delay(10);\r
+  }\r
+}\r