#include <TM1637.h>
const int CLK = 4;
const int DIO = 5;
TM1637 tm(CLK, DIO);
const int BUZZ = 13;
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 34;
// variable for storing the potentiometer value
int potValue = 0;
int oldValue = 0;
void setup() {
tm.init();
tm.set(BRIGHT_TYPICAL);
delay(3000);
beep(500);
}
void loop() {
tm.display(0, (potValue / 10) % 10);
tm.display(1, potValue % 10);
tm.display(2, 0);
tm.display(3, 0);
oldValue = potValue;
// Reading potentiometer value
potValue = 1+analogRead(potPin)/137;
delay(100);
if(potValue != oldValue) beep(20);
}
void beep(unsigned char delayms){
analogWrite(BUZZ, 5); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // wait for a delayms ms
analogWrite(BUZZ, 0); // 0 turns it off
delay(delayms); // wait for a delayms ms
}