PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

118 行
3.3KB

  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. }