PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

scroll_serial.ino 3.3KB

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. HCMS Display
  3. Language: Arduino/Wiring
  4. Displays a string on an Avago HCMS-297x display
  5. Scrolls the current display string as well.
  6. Anything you send in the serial port is displayed
  7. when the Arduino receives a newline or carriage return.
  8. String library based on the Wiring String library:
  9. http://wiring.org.co/learning/reference/String.html
  10. created 12 Jun. 2008
  11. modified 11 March 2010
  12. by Tom Igoe
  13. */
  14. #include <WString.h>
  15. #include <LedDisplay.h>
  16. #define maxStringLength 180 // max string length
  17. // Define pins for the LED display.
  18. // You can change these, just re-wire your board:
  19. #define dataPin 6 // connects to the display's data in
  20. #define registerSelect 7 // the display's register select pin
  21. #define clockPin 8 // the display's clock pin
  22. #define enable 9 // the display's chip enable pin
  23. #define reset 10 // the display's reset pin
  24. #define displayLength 8 // number of chars in the display
  25. // create am instance of the LED display:
  26. LedDisplay myDisplay = LedDisplay(dataPin, registerSelect, clockPin,
  27. enable, reset, displayLength);
  28. int brightness = 15; // screen brightness
  29. String displayString; // the string currently being displayed
  30. String bufferString; // the buffer for receiving incoming characters
  31. void setup() {
  32. Serial.begin(9600);
  33. // set an initial string to display:
  34. displayString = "Use the Arduino Serial Monitor to send a new string.";
  35. // initialize the display library:
  36. myDisplay.begin();
  37. // set the display string, speed,and brightness:
  38. myDisplay.setString(displayString.c_str());
  39. myDisplay.setBrightness(brightness);
  40. }
  41. void loop() {
  42. // get new data in from the serial port:
  43. while (Serial.available() > 0) {
  44. // read in new serial:
  45. getSerial();
  46. }
  47. // srcoll left and right:
  48. /*if ((myDisplay.getCursor() >= 0) ||
  49. (myDisplay.getCursor() <= -(myDisplay.stringLength() - 8))) {
  50. myDirection = -myDirection;
  51. delay(1000);
  52. }
  53. */
  54. if (myDisplay.getCursor() <= -(myDisplay.stringLength() - 8)) {
  55. // when the string reaches the end, stop and then fade out
  56. delay(500);
  57. for (int n=brightness; n >= 0; n--) {
  58. myDisplay.setBrightness(n);
  59. delay(50);
  60. }
  61. // start the string back from the beginning
  62. myDisplay.setCursor(0);
  63. myDisplay.scroll(0);
  64. // fade back in
  65. for (int n=1; n <= brightness; n++) {
  66. myDisplay.setBrightness(n);
  67. delay(25);
  68. }
  69. delay(500);
  70. return;
  71. }
  72. myDisplay.scroll(-1); // direction of scrolling. -1 = left, 1 = right.
  73. delay(100);
  74. }
  75. void getSerial() {
  76. // get a new byte in the serial port:
  77. int inByte = Serial.read();
  78. switch (inByte) {
  79. case '\n':
  80. case '\r':
  81. // if you get a newline,
  82. // copy the buffer into the displayString:
  83. displayString = bufferString;
  84. // set the display with the new string:
  85. myDisplay.setString(displayString.c_str());
  86. // set the cursor, so the old string fade away now
  87. myDisplay.setCursor(-1000);
  88. // clear the buffer:
  89. bufferString = "";
  90. break;
  91. default:
  92. // if you get any ASCII alphanumeric value
  93. // (i.e. anything greater than a space), add it to the buffer:
  94. if (inByte >= ' ') {
  95. if (bufferString.length() < maxStringLength) {
  96. bufferString.concat(char(inByte));
  97. }
  98. }
  99. break;
  100. }
  101. }