Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // All the mcufriend.com UNO shields have the same pinout.
- // i.e. control pins A0-A4. Data D2-D9. microSD D10-D13.
- // Touchscreens are normally A1, A2, D7, D6 but the order varies
- //
- // This demo should work with most Adafruit TFT libraries
- // If you are not using a shield, use a full Adafruit constructor()
- // e.g. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- #define LCD_CS A3 // Chip Select goes to Analog 3
- #define LCD_CD A2 // Command/Data goes to Analog 2
- #define LCD_WR A1 // LCD Write goes to Analog 1
- #define LCD_RD A0 // LCD Read goes to Analog 0
- #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
- #include <SPI.h> // f.k. for Arduino-1.5.2
- #include "Adafruit_GFX.h"// Hardware-specific library
- #include <MCUFRIEND_kbv.h>
- MCUFRIEND_kbv tft;
- //#include <Adafruit_TFTLCD.h>
- //Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- // Assign human-readable names to some common 16-bit color values:
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- #ifndef min
- #define min(a, b) (((a) < (b)) ? (a) : (b))
- #endif
- void setup(void);
- void loop(void);
- void setup(void) {
- Serial.begin(9600);
- uint32_t when = millis();
- // while (!Serial) ; //hangs a Leonardo until you connect a Serial
- if (!Serial) delay(5000); //allow some time for Leonardo
- Serial.println("Serial took " + String((millis() - when)) + "ms to start");
- // tft.reset(); //hardware reset
- uint16_t ID = tft.readID(); //
- Serial.print("ID = 0x");
- Serial.println(ID, HEX);
- if (ID == 0xD3D3) ID = 0x9481; // write-only shield
- // ID = 0x9329; // force ID
- tft.begin(ID);
- }
- void printmsg(int row, const char *msg)
- {
- tft.setTextColor(YELLOW, BLACK);
- tft.setCursor(0, row);
- tft.println(msg);
- }
- void loop(void) {
- tft.fillScreen(BLACK);
- float pressureRawValue = 0.0;
- pressureRawValue = analogRead(A0);
- float pressureKpaValue = pressureRawValue * 63.529 + 5.411;
- float pressureBarValue = pressureKpaValue * 0.01;
- char* s;
- sprintf(s, "Raw %.4f V", pressureRawValue);
- printmsg(0, s);
- sprintf(s, "kPA %.4f kPA", pressureKpaValue);
- printmsg(1, s);
- sprintf(s, "BAR %.4f bar", pressureBarValue);
- printmsg(2, s);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement