#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TM1637.h>
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 5; // the number of the pushbutton pin
const int CLK = 3;
const int DIO = 2;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
LiquidCrystal_I2C lcd(0x27,16,2);
TM1637 tm(CLK, DIO);
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0); // set cursor to 1 symbol of 1 line
lcd.print("Arduino Lessons:");
lcd.setCursor(0,1); // set cursor to 1 symbol of 2 line
lcd.print("www.andjey.info");
tm.init();
tm.set(7);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
//trigger launch
lcd.clear();
lcd.setCursor(0,0); // set cursor to 1 symbol of 1 line
lcd.print("Launching");
countdown();
}
}
void countdown() {
int countdownlength = 5;
while(countdownlength > 0)
{
tm.display(0, countdownlength);
delay(1000);
countdownlength--;
}
timer();
}
void timer() {
int timer = 0;
while(true)
{
tm.display(3, timer % 10);
tm.display(2, timer / 10 % 10);
tm.display(1, timer / 100 % 10);
tm.display(0, timer / 1000 % 10);
lcd.setCursor(0,0); // set cursor to 1 symbol of 1 line
lcd.print("Launched........");
delay(1000);
timer++;
}
}