#include <TM1637.h>
const int CLK = 4;
const int DIO = 5;
TM1637 tm(CLK, DIO);
const int BUZZ = 13;
const int BUTT = 14;
const int SPOT = 18;
// 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;
int buttstate = 0;
int warmup = 0;
void setup() {
tm.init();
tm.set(BRIGHT_TYPICAL);
pinMode(BUZZ, OUTPUT);
pinMode(BUTT, INPUT);
pinMode(SPOT, OUTPUT);
delay(3000);
beep(100);
}
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)/410;
delay(100);
if(potValue != oldValue) beep(20);
// Read button and Spot
buttstate = digitalRead(BUTT);
if(buttstate == 1 ) {
if(warmup == 0){
beep(100);
warmup = 1;
digitalWrite(SPOT, HIGH);
delay(potValue*100);
digitalWrite(SPOT, LOW);
beep(100);
beep(100);
}
}
delay(20);
if(warmup == 1){
delay(2000);
warmup = 0;
beep(1000);
}
}
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
}