//Digital Object Counter
#include <TM1637Display.h>
const int CLK2 =2;
const int DIO = 3;
TM1637Display display(CLK2, DIO);
int IRPin = 4;
int buzzerPin = 5;
int ledPin=6;
int buttonPin = 7;
int n = 0;
int oldValue = 0;
int last=10;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(IRPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
display.setBrightness(7);
}
void loop() {
// put your main code here, to run repeatedly:
if(last>n){
if (digitalRead(IRPin) == 0 && oldValue == 1) {
oldValue = 0;
Count();
} else if (digitalRead(IRPin) == 1 && oldValue == 0) {
oldValue = 1;
}}
if (digitalRead(buttonPin) == 0) {
Reset();
}
if(n==last){
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
}
display.showNumberDec(n, false);
Serial.println(n);
delay(1);
}
void Count() {
n = n + 1;
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
}
void Reset() {
n = 0;
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
}