//CODED BY AHMAD KUSHAIRI AND HAIQAL IMANSHAH
#include <TM1637Display.h>
#define echoPin 2
#define trigPin 3
#define resetPin 4
#define CLK 8
#define DIO 9
TM1637Display display(CLK, DIO);
float duration;
float cm;
long numDisplay=100;
boolean trigUp = false;
boolean trigDown = false;
float counterPushUp=0;
int buzzer=7;
void setup() {
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(resetPin,INPUT_PULLUP);
display.setBrightness(4);
display.clear();
delay(50);
display.showNumberDecEx(numDisplay, false, true, 4, 0);
}
void loop() {
if(digitalRead(resetPin)==0){
trigUp=false;
trigDown=false;
counterPushUp=0;
}
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(50);
duration = pulseIn(echoPin,HIGH);
cm = duration * 0.045/5.;
if (cm>30 && cm<=80){
trigUp = true;
}
else if (cm < 15){
trigDown = true;
}
else if(cm >30) {
}
if (trigUp==true && trigDown==true){
counterPushUp=counterPushUp+0.5;
trigUp=false;
delay(50);
tone(7,800,40);
trigDown=false;
}
display.showNumberDecEx(counterPushUp, false, true, 4, 0);
}