Guest User

Untitled

a guest
Jun 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include "SSD1306.h"
  2. const int isObstaclePin = 0; // set number of the tilt switch pin D3 (0)
  3.  
  4.  
  5. SSD1306 display(0x3c, 5, 4); // Pin D1 = 5 / Pin D2 = 4
  6.  
  7. String obstacle;
  8. int isObstacle = HIGH;
  9.  
  10. void setup() {
  11.  
  12. Serial.begin(115200);
  13. pinMode(isObstaclePin, INPUT);
  14. display.init();
  15. display.flipScreenVertically();
  16.  
  17. display.clear();
  18. drawDistance();
  19. display.display();
  20. }
  21.  
  22. void loop() {
  23.  
  24. drawDistance();
  25. display.display();
  26.  
  27. }
  28.  
  29. void drawDistance() {
  30. delay(2000);
  31.  
  32. isObstacle = digitalRead(isObstaclePin);
  33.  
  34. obstacle = "It is Ok!";
  35.  
  36. if (isObstacle == LOW){
  37. obstacle = "OBSTACLE!";
  38. }
  39.  
  40.  
  41. display.clear();
  42. display.setTextAlignment(TEXT_ALIGN_LEFT);
  43. display.setFont(ArialMT_Plain_10);
  44. display.drawString(0, 0, "Alert: "+obstacle);
  45.  
  46. }
Add Comment
Please, Sign In to add comment