// TM1637 SevenSegment Counter Wokwi Example
//
// https://wokwi.com/projects/339227323398095442
#include <TM1637.h>
#include <Servo.h>
const int CLK = 2;
const int DIO = 3;
int potPin = 2; // select the input pin for the potentiometer
int val = 0;
Servo myservo;
int pos=0;
int sound = 1500;
TM1637 tm(CLK, DIO);
void setup() {
tm.init();
tm.set(BRIGHT_TYPICAL);
myservo.attach(4);
myservo.write(180);
}
unsigned int counter = 100;
void loop() {
while(counter > 0){
val = analogRead(potPin);
tm.display(0, (counter / 1000) % 10);
tm.display(1, (counter / 100) % 10);
tm.display(2, (counter / 10) % 10);
tm.display(3, counter % 10);
if(counter <6){
tone(7,sound,val);
delay(val);
sound = sound - 250;
}
delay(val);
counter--;
if (counter == 0) {
tm.display(0, (counter / 1000) % 10);
tm.display(1, (counter / 100) % 10);
tm.display(2, (counter / 10) % 10);
tm.display(3, counter % 10);
tone(7,sound,1000);
delay(1000);
myservo.write(0);
delay(1000);
break;
}
}
}