Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- #define trigPin 13
- #define echoPin 12
- int counter = 0;
- int currentState = 0;
- int previousState = 0;
- void setup() {
- Serial.begin (9600);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- }
- void loop() {
- lcd.begin(16,2); // sixteen characters across - 2 lines
- // first character - 1st line
- lcdbacklight();
- lcd.setCursor(0,0);
- lcd.print(counter);
- lcd.clear();
- lcd.print(counter);
- long duration, distance;
- digitalWrite(trigPin, LOW);
- delayMicroseconds(1000);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(1000);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = (duration/1) / 29.1;
- if (distance <= 10){
- currentState = 1;
- }
- else {
- currentState = 0;
- }
- delay(500);
- if(currentState != previousState){
- if(currentState == 1){
- counter = counter + 1;
- Serial.println(counter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement