hey iedereen,
ik raak er niet uit.
#include <TM1637Display.h>
#include <TimerOne.h>
byte mins = 0, secs = 0;
volatile byte ts = 0, tm;
#defineMIN_KEY_PRESSED (!(PINB & (1<<0)))
#defineSEC_KEY_PRESSED(!(PINB & (1<<1)))
#defineSTART_KEY_PRESSED (!(PINB & (1<<2)))
void setup() {
DDRB = 000000;
DDRC = 0b00001111;
DDRD = 0b11111111;
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
pinMode(13, OUTPUT);
Timer1.initialize(1000000);
Timer1.atachInterrupt(updateTime);
}
void loop() {
digitalWrite(13, LOW);
While (!START_KEY_PRESSED) {
if (MIN_KEY_PRESSED){
if (mins < 59){
mins++;
}
else {
mins=0;
}
numberOutput(mins * 100+secs);
for (int i=0; i<300; i++) {
refresh();
}
}
if (SEC_KEY_PRESSED) {
if (secs < 59) {
secs++;
}
else {
secs = 0;
}
numberOutput(mins * 100 + secs);
for (int i = 0; i < 300; i++) {
refresh();
}
}
numberOutput (mins*100+secs);
refresh();
}
ts = secs;
tm = mins;
while ((tm > 0)| (ts > 0)) {
numberOutput(tm * 100 + ts);
refresh();
}
digitalWrite(13, HIGH);
numberOutput(0000);
for (int i = 0; i < 3000; i++) {
refresh();
}
while (!START_KEY_PRESSED) {
for (int i = 0; i < 300; i++) {
refresh();
}
numberOutput (0000);
delay(300);
}
while (START_KEY_PRESSED);
}
void updateTime() {
if (ts > 0 {
ts--;
}
else {
ts=59;
if (tm > 0) {
tm--;
}
}
}