#include <TM1637Display.h>
// Define the TM1637 display pins
#define CLK_PIN 4
#define DIO_PIN 5
TM1637Display displayTM1637(CLK_PIN, DIO_PIN);
const int sensorPin = 2;
volatile int objects = 0;
unsigned long previousMillis = 0;
int rpm = 0;
void setup() {
// Initialize the TM1637 display
displayTM1637.setBrightness(0x0F); // Set the brightness to maximum
pinMode(sensorPin, INPUT_PULLUP); // Assuming your sensor is connected to pin 2
attachInterrupt(digitalPinToInterrupt(sensorPin), count, FALLING);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 1000) {
rpm = (objects / 1.0) * 60;
objects = 0;
previousMillis = currentMillis;
}
// Display the RPM value on the TM1637 display
displayTM1637.showNumberDec(rpm);
// You can also print the RPM to the Serial monitor if needed
Serial.println("RPM: " + String(rpm));
delay(100);
}
void count() {
objects++;
}