Advertisement
RamiChan

FinalCodeEdit

Apr 29th, 2016
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. // scrolltext demo for Adafruit RGBmatrixPanel library.
  2. // Demonstrates double-buffered animation on our 16x32 RGB LED matrix:
  3. // http://www.adafruit.com/products/420
  4.  
  5. // Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
  6. // for Adafruit Industries.
  7. // BSD license, all text above must be included in any redistribution.
  8.  
  9. float tempC;
  10. int tempPin = A5;
  11.  
  12.  
  13.  
  14. #include <Adafruit_GFX.h> // Core graphics library
  15. #include <RGBmatrixPanel.h> // Hardware-specific library
  16.  
  17.  
  18. #define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
  19. #define LAT A3
  20. #define OE 9
  21. #define A A0
  22. #define B A1
  23. #define C A2
  24. // Last parameter = 'true' enables double-buffering, for flicker-free,
  25. // buttery smooth animation. Note that NOTHING WILL SHOW ON THE DISPLAY
  26. // until the first call to swapBuffers(). This is normal.
  27. RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
  28. // Double-buffered mode consumes nearly all the RAM available on the
  29. // Arduino Uno -- only a handful of free bytes remain. Even the
  30. // following string needs to go in PROGMEM:
  31.  
  32. #define STRING_SIZE 32
  33.  
  34. char str[STRING_SIZE]; //the string to scroll
  35. char tempBuffer[8]; //storage for the temperature substring
  36.  
  37. int textX = matrix.width(),
  38. textMin = sizeof(str) * -12,
  39. hue = 0;
  40.  
  41.  
  42. void setup() {
  43. matrix.begin();
  44. matrix.setTextWrap(false); // Allow text to run off right edge
  45. matrix.setTextSize(2);
  46.  
  47. Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
  48.  
  49. }
  50. uint32_t temptimer = millis();
  51. void loop() {
  52. byte i;
  53.  
  54. if ((millis() - temptimer) > 3500)
  55. {
  56. temptimer = millis();
  57. tempC = analogRead(tempPin); //read the value from the sensor
  58. tempC = (5.0 * tempC * 10.0)/1024.0; //convert the analog data to temperature
  59. Serial.print(tempC); //send the data to the computer
  60.  
  61.  
  62. snprintf(str, STRING_SIZE-1, "Current Temperature is %sC", dtostrf(tempC, 6, 2, tempBuffer));
  63.  
  64. }
  65. // Clear background
  66. matrix.fillScreen(0);
  67.  
  68. matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true));
  69. matrix.setCursor(textX, 1);
  70. matrix.print(str);
  71.  
  72. // Move text left (w/wrap), increase hue
  73. if((--textX) < textMin) textX = matrix.width();
  74. hue += 7;
  75. if(hue >= 1536) hue -= 1536;
  76.  
  77. // Update display
  78. matrix.swapBuffers(false);
  79. delay(15);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement