Advertisement
KRITSADA

POP-XT with HC-SR04 Show value on GLCD

Aug 27th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. //******************************************
  2. // POP-XT with HC-SR04 Show value on GLCD
  3. //******************************************
  4. #include <popxt.h>
  5. #define TRIG 2
  6. #define ECHO 3
  7.  
  8. void setup() {  
  9.   setTextSize(2);
  10.   glcdMode(3);
  11. }
  12.  
  13. void loop() {
  14. long RAW,DIST;
  15.   out(TRIG,HIGH);
  16.   delayMicroseconds(10);  
  17.   out(TRIG, LOW);
  18.   RAW=pulseIn(ECHO,HIGH);
  19.   DIST=(RAW/2)/29.1;
  20.   glcd(0,0,"RAW=%l   ",RAW);
  21.   glcd(1,0,"DIST=%l  CM   ",DIST);
  22.   delay(100);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement