Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include "Adafruit_GFX.h"
  2. #include "Adafruit_ILI9341.h"
  3.  
  4. #define TFT_DC 9
  5. #define TFT_CS 10
  6. #define TFT_RST 8
  7. #define TFT_MISO 12
  8. #define TFT_MOSI 11
  9. #define TFT_CLK 13
  10.  
  11. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
  12.  
  13.  
  14. int analogInput = 0;
  15. float vout = 0.0;
  16. float vin = 0.0;
  17. float R1 = 100300.0; // resistance of R1 (100K) -see text!
  18. float R2 = 9880.0; // resistance of R2 (10K) - see text!
  19. int value = 0;
  20.  
  21. void setup() {
  22. Serial.begin(9600);
  23.  
  24. tft.begin();
  25. tft.fillScreen(ILI9341_BLACK);
  26. tft.drawRect(0, 0, 120, 160 , ILI9341_GREEN);
  27. tft.drawRect(120, 0, 240, 160 , ILI9341_GREEN);
  28.  
  29. tft.drawRect(0, 160, 120, 320 , ILI9341_GREEN);
  30. tft.drawRect(120, 160, 240, 320 , ILI9341_GREEN);
  31.  
  32. pinMode(analogInput, INPUT);
  33.  
  34. void setRotation(uint8_t rotation);
  35. }
  36.  
  37. void loop() {
  38.  
  39. // read the value at analog input
  40. value = analogRead(analogInput);
  41. vout = (value * 4.770) / 1024.0; // see text
  42. vin = vout / (R2/(R1+R2));
  43. if (vin<0.09) {
  44. vin=0.0;//statement to quash undesired reading !
  45. }
  46.  
  47. ////////////////////////// 1° QUADRANTE /////////////////////////////
  48.  
  49. tft.setCursor(2,51);
  50. tft.setTextColor(ILI9341_YELLOW);
  51. tft.setTextSize(1);
  52. tft.setRotation(3);
  53. tft.println("TENSIONE:");
  54.  
  55. tft.setCursor(50,45 );
  56. tft.setTextColor(ILI9341_WHITE);
  57. tft.setTextSize(2);
  58. tft.setRotation(3);
  59. tft.println(vin);
  60.  
  61. ////////////////////////// 2° QUADRANTE /////////////////////////////
  62.  
  63. tft.setCursor(163,51);
  64. tft.setTextColor(ILI9341_YELLOW);
  65. tft.setTextSize(1);
  66. tft.setRotation(3);
  67. tft.println("TENSIONE:");
  68.  
  69. tft.setCursor(211,45 );
  70. tft.setTextColor(ILI9341_WHITE);
  71. tft.setTextSize(2);
  72. tft.setRotation(3);
  73. tft.println(vin);
  74.  
  75. ////////////////////////// 3° QUADRANTE /////////////////////////////
  76.  
  77. tft.setCursor(2,171);
  78. tft.setTextColor(ILI9341_YELLOW);
  79. tft.setTextSize(1);
  80. tft.setRotation(3);
  81. tft.println("TENSIONE:");
  82.  
  83. tft.setCursor(50,165 );
  84. tft.setTextColor(ILI9341_WHITE);
  85. tft.setTextSize(2);
  86. tft.setRotation(3);
  87. tft.println(vin);
  88.  
  89. ////////////////////////// 4° QUADRANTE /////////////////////////////
  90.  
  91. tft.setCursor(163,171);
  92. tft.setTextColor(ILI9341_YELLOW);
  93. tft.setTextSize(1);
  94. tft.setRotation(3);
  95. tft.println("TENSIONE:");
  96.  
  97. tft.setCursor(211,165 );
  98. tft.setTextColor(ILI9341_WHITE);
  99. tft.setTextSize(2);
  100. tft.setRotation(3);
  101. tft.println(vin);
  102.  
  103. delay(500);
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement