Stap 3: Kod
int uur = 9;
int minuut = 29;
int firstpin = 6;
int secondpin = 7;
int thirdpin = 8;
int fourthpin = 9;
int prevmillis;
int interval = 50; int tweede;
int firstanode = 2;
int secondanode = 3;
int thirdanode = 4; int fourthanode = 5;
VOID Setup {}
pinMode (7, OUTPUT);
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (A0, INPUT_PULLUP);
pinMode (A1, INPUT_PULLUP);
pinMode (A2, INPUT_PULLUP);
pinMode (A3, INPUT_PULLUP);
Serial.begin(9600); }
void loop {}
Als ((millis()-prevmillis) > interval) {prevmillis = millis(); tweede ++;
Als (tweede == 60) {tweede = 0; minuut ++;}
Als (minuut 60 ==) {minuut = 0; uur ++;}
if(hour==24) {uur = 0;}} Als interval
als graven Lees (a0) == lage //minute++ //id digr Lees a1 == lage //minute--
Displaytime (uur, minuut); } //loop
Displatbars (temp, hum);
Kolla knappar, kolla därefter
VOID Displaytime (int hour_, int minute_) {}
int digit2 = hour_ % 10;
entals siffran uur
int digit1 = hour_ - digit2 * 10;
tiotalsiffran uur
int digit4 = minute_ % 10;
entals siffran minuten
int digit3 = minute_ - digit4 * 10;
tiotalsiffran minuut
Serial.Print(digit1);
Serial.Print(digit2);
Serial.Print(digit3);
Serial.println(Digit4);
digitalWrite (firstanode, hoge);
BCDwrite(digit1);
vertraging(20); digitalWrite (2, laag);
digitalWrite (secondanode, hoge);
BCDwrite(digit2);
vertraging(20);
digitalWrite (3, laag);
digitalWrite (thirdanode, hoge);
BCDwrite(digit3);
vertraging(20);
digitalWrite (4, laag);
digitalWrite (fourthanode, hoge);
BCDwrite(digit4);
vertraging(20);
digitalWrite (5, laag); }
VOID BCDwrite (int-nummer) //0-9
{
digitalWrite (firstpin, bitRead (nummer, 0));
digitalWrite (secondpin), bitRead (nummer, 1);
digitalWrite (thirdpin, bitRead (nummer, 2));
digitalWrite (fourthpin, bitRead (nummer, 3)); }