sevenseg.ino 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***************************************************
  2. This is a library for our I2C LED Backpacks
  3. Designed specifically to work with the Adafruit LED 7-Segment backpacks
  4. ----> http://www.adafruit.com/products/881
  5. ----> http://www.adafruit.com/products/880
  6. ----> http://www.adafruit.com/products/879
  7. ----> http://www.adafruit.com/products/878
  8. These displays use I2C to communicate, 2 pins are required to
  9. interface. There are multiple selectable I2C addresses. For backpacks
  10. with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
  11. with 3 Address Select pins: 0x70 thru 0x77
  12. Adafruit invests time and resources providing this open source code,
  13. please support Adafruit and open-source hardware by purchasing
  14. products from Adafruit!
  15. Written by Limor Fried/Ladyada for Adafruit Industries.
  16. BSD license, all text above must be included in any redistribution
  17. ****************************************************/
  18. #include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
  19. #include <Adafruit_GFX.h>
  20. #include "Adafruit_LEDBackpack.h"
  21. Adafruit_7segment matrix = Adafruit_7segment();
  22. void setup() {
  23. #ifndef __AVR_ATtiny85__
  24. Serial.begin(9600);
  25. Serial.println("7 Segment Backpack Test");
  26. #endif
  27. matrix.begin(0x70);
  28. }
  29. void loop() {
  30. // try to print a number thats too long
  31. matrix.print(10000, DEC);
  32. matrix.writeDisplay();
  33. delay(500);
  34. // print a hex number
  35. matrix.print(0xBEEF, HEX);
  36. matrix.writeDisplay();
  37. delay(500);
  38. // print a floating point
  39. matrix.print(12.34);
  40. matrix.writeDisplay();
  41. delay(500);
  42. // print with print/println
  43. for (uint16_t counter = 0; counter < 9999; counter++) {
  44. matrix.println(counter);
  45. matrix.writeDisplay();
  46. delay(10);
  47. }
  48. // method #2 - draw each digit
  49. uint16_t blinkcounter = 0;
  50. boolean drawDots = false;
  51. for (uint16_t counter = 0; counter < 9999; counter ++) {
  52. matrix.writeDigitNum(0, (counter / 1000), drawDots);
  53. matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);
  54. matrix.drawColon(drawDots);
  55. matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);
  56. matrix.writeDigitNum(4, counter % 10, drawDots);
  57. blinkcounter+=50;
  58. if (blinkcounter < 500) {
  59. drawDots = false;
  60. } else if (blinkcounter < 1000) {
  61. drawDots = true;
  62. } else {
  63. blinkcounter = 0;
  64. }
  65. matrix.writeDisplay();
  66. delay(10);
  67. }
  68. }