Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <Adafruit_GFX.h>
  2. #include <Adafruit_ILI9340.h>
  3. #include <TFT.h>
  4. #include <SPI.h>
  5.  
  6. // pin definition for the Uno
  7. #define cs 10
  8. #define dc 9
  9. #define rst 8
  10.  
  11.  
  12.  
  13. TFT TFTscreen = TFT(cs, dc, rst);
  14.  
  15. // position of the line on screen
  16. int xPos = 0;
  17.  
  18. void setup() {
  19. // initialize the serial port
  20. Serial.begin(9600);
  21.  
  22. // initialize the display
  23. TFTscreen.begin();
  24.  
  25. // clear the screen with a pretty color
  26. TFTscreen.background(250, 16, 200);
  27. }
  28.  
  29. void loop() {
  30. // read the sensor and map it to the screen height
  31. int sensor = analogRead(A0);
  32. int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height());
  33.  
  34. // print out the height to the serial monitor
  35. Serial.println(drawHeight);
  36.  
  37. // draw a line in a nice color
  38. TFTscreen.stroke(250, 180, 10);
  39. TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height());
  40.  
  41. // if the graph has reached the screen edge
  42. // erase the screen and start again
  43. if (xPos >= 160) {
  44. xPos = 0;
  45. TFTscreen.background(250, 16, 200);
  46. }
  47. else {
  48. // increment the horizontal position:
  49. xPos++;
  50. }
  51.  
  52. delay(16);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement