Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <UTFT.h>
- #include <NewPing.h>
- #define TRIGGER_PIN 5 // Arduino pin tied to trigger pin on the ultrasonic sensor.
- #define ECHO_PIN 3 // Arduino pin tied to echo pin on the ultrasonic sensor.
- #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
- NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
- //for QD_TFT180X SPI LCD Modle
- //Param1:Value Can be:QD_TFT180A/QD_TFT180B/QD_TFT180C
- //Param2 instructions:Connect to LCD_Pin #4 SDA/SDI/MOSI(it means LCD_Model Pin_SDA/SDI/MOSI Connect to Arduino_UNO Pin11)
- //Param3 instructions:Connect to LCD_Pin #5 SCL/CLK/SCLK(it means LCD_Model Pin_SCL/CLK/SCLK Connect to Arduino_UNO Pin10)
- //Param4 instructions:Connect to LCD_Pin #2 CS/CE(it means LCD_Model Pin_CS/CE Connect to Arduino_UNO Pin9)
- //Param5 instructions:Connect to LCD_Pin #1 RST/RESET(it means LCD_Model Pin_RST/RESET Connect to Arduino_UNO Pin12)
- //Param6 instructions:Connect to LCD_Pin #3 RS/DC(it means LCD_Model Pin_RS/DC Connect to Arduino_UNO Pin8)
- // #6 & #7 to 5V
- // #8 to GND
- UTFT myGLCD(QD_TFT180A,11,10,9,12,8); // Remember to change the model parameter to suit your display module!
- // Declare which fonts we will be using
- extern uint8_t SmallFont[];
- extern uint8_t SevenSegNumFont[];
- void setup()
- {
- // Setup the LCD
- myGLCD.InitLCD(); // initiaise the screen;
- myGLCD.setFont(SmallFont); // use the SmallFont (also available: BigFont and SevenSegNumFont)
- myGLCD.clrScr(); // clear the screen
- myGLCD.setColor(255, 255, 255); // set colour white (NOTE: BGR and not RGB)
- myGLCD.print("Distance in cm:",CENTER, 1); // print header 1 pixel down and at center
- }
- void loop()
- {
- delay(50); // delay for sonar ping
- int uS = sonar.ping_cm(); // uS will be the ping distance in CM
- Serial.begin(9600);
- Serial.println(uS); // serial print the distance
- myGLCD.setColor(255,255,0); // set colour to light blue
- myGLCD.setFont(SevenSegNumFont); // use SevenSegNumFont
- myGLCD.print(String(uS)+String(" "), LEFT, 24); // print distance as a string and add a space to eraase pevious reading
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement