Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // All the mcufriend.com UNO shields have the same pinout.
  2. // i.e. control pins A0-A4.  Data D2-D9.  microSD D10-D13.
  3. // Touchscreens are normally A1, A2, D7, D6 but the order varies
  4. //
  5. // This demo should work with most Adafruit TFT libraries
  6. // If you are not using a shield,  use a full Adafruit constructor()
  7. // e.g. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  8.  
  9. #define LCD_CS A3 // Chip Select goes to Analog 3
  10. #define LCD_CD A2 // Command/Data goes to Analog 2
  11. #define LCD_WR A1 // LCD Write goes to Analog 1
  12. #define LCD_RD A0 // LCD Read goes to Analog 0
  13. #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  14.  
  15. #include <SPI.h>          // f.k. for Arduino-1.5.2
  16. #include "Adafruit_GFX.h"// Hardware-specific library
  17. #include <MCUFRIEND_kbv.h>
  18. MCUFRIEND_kbv tft;
  19. //#include <Adafruit_TFTLCD.h>
  20. //Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  21.  
  22. // Assign human-readable names to some common 16-bit color values:
  23. #define BLACK   0x0000
  24. #define BLUE    0x001F
  25. #define RED     0xF800
  26. #define GREEN   0x07E0
  27. #define CYAN    0x07FF
  28. #define MAGENTA 0xF81F
  29. #define YELLOW  0xFFE0
  30. #define WHITE   0xFFFF
  31.  
  32. #ifndef min
  33. #define min(a, b) (((a) < (b)) ? (a) : (b))
  34. #endif
  35.  
  36. void setup(void);
  37. void loop(void);
  38.  
  39.  
  40.  
  41. void setup(void) {
  42.   Serial.begin(9600);
  43.   uint32_t when = millis();
  44.   //    while (!Serial) ;   //hangs a Leonardo until you connect a Serial
  45.   if (!Serial) delay(5000);           //allow some time for Leonardo
  46.   Serial.println("Serial took " + String((millis() - when)) + "ms to start");
  47.   //    tft.reset();                 //hardware reset
  48.   uint16_t ID = tft.readID(); //
  49.   Serial.print("ID = 0x");
  50.   Serial.println(ID, HEX);
  51.   if (ID == 0xD3D3) ID = 0x9481; // write-only shield
  52.   //    ID = 0x9329;                             // force ID
  53.   tft.begin(ID);
  54. }
  55.  
  56.  
  57. void printmsg(int row, const char *msg)
  58. {
  59.   tft.setTextColor(YELLOW, BLACK);
  60.   tft.setCursor(0, row);
  61.   tft.println(msg);
  62. }
  63.  
  64. void loop(void) {
  65.  
  66.   tft.fillScreen(BLACK);
  67.  
  68.   float pressureRawValue =  0.0;
  69.   pressureRawValue = analogRead(A0);
  70.  
  71.   float pressureKpaValue = pressureRawValue * 63.529 + 5.411;
  72.   float pressureBarValue = pressureKpaValue * 0.01;
  73.  
  74.  
  75.   char* s;
  76.   sprintf(s, "Raw %.4f V", pressureRawValue);
  77.   printmsg(0, s);
  78.   sprintf(s, "kPA %.4f kPA", pressureKpaValue);
  79.   printmsg(1, s);
  80.   sprintf(s, "BAR %.4f bar", pressureBarValue);
  81.   printmsg(2, s);
  82.  
  83.   delay(1000);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement