quadalphanum.ino 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Demo the quad alphanumeric display LED backpack kit
  2. // scrolls through every character, then scrolls Serial
  3. // input onto the display
  4. #include <Wire.h>
  5. #include <Adafruit_GFX.h>
  6. #include "Adafruit_LEDBackpack.h"
  7. Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
  8. void setup() {
  9. Serial.begin(9600);
  10. alpha4.begin(0x70); // pass in the address
  11. alpha4.writeDigitRaw(3, 0x0);
  12. alpha4.writeDigitRaw(0, 0xFFFF);
  13. alpha4.writeDisplay();
  14. delay(200);
  15. alpha4.writeDigitRaw(0, 0x0);
  16. alpha4.writeDigitRaw(1, 0xFFFF);
  17. alpha4.writeDisplay();
  18. delay(200);
  19. alpha4.writeDigitRaw(1, 0x0);
  20. alpha4.writeDigitRaw(2, 0xFFFF);
  21. alpha4.writeDisplay();
  22. delay(200);
  23. alpha4.writeDigitRaw(2, 0x0);
  24. alpha4.writeDigitRaw(3, 0xFFFF);
  25. alpha4.writeDisplay();
  26. delay(200);
  27. alpha4.clear();
  28. alpha4.writeDisplay();
  29. // display every character,
  30. for (uint8_t i='!'; i<='z'; i++) {
  31. alpha4.writeDigitAscii(0, i);
  32. alpha4.writeDigitAscii(1, i+1);
  33. alpha4.writeDigitAscii(2, i+2);
  34. alpha4.writeDigitAscii(3, i+3);
  35. alpha4.writeDisplay();
  36. delay(300);
  37. }
  38. Serial.println("Start typing to display!");
  39. }
  40. char displaybuffer[4] = {' ', ' ', ' ', ' '};
  41. void loop() {
  42. while (! Serial.available()) return;
  43. char c = Serial.read();
  44. if (! isprint(c)) return; // only printable!
  45. // scroll down display
  46. displaybuffer[0] = displaybuffer[1];
  47. displaybuffer[1] = displaybuffer[2];
  48. displaybuffer[2] = displaybuffer[3];
  49. displaybuffer[3] = c;
  50. // set every digit to the buffer
  51. alpha4.writeDigitAscii(0, displaybuffer[0]);
  52. alpha4.writeDigitAscii(1, displaybuffer[1]);
  53. alpha4.writeDigitAscii(2, displaybuffer[2]);
  54. alpha4.writeDigitAscii(3, displaybuffer[3]);
  55. // write it out!
  56. alpha4.writeDisplay();
  57. delay(200);
  58. }