/* Současné ovladače 5587904 5587760 5587952 5587724 5587916 5587772 1377728 1377584 1377776 1377548 1377740 1377596 1377788 1377539 */ #include #include int stav = 0; // 1=nastaveni, 2=readytostart, 3=polocas1, 4=pauza, 5=polocas2, 6=konec int minuta, delka = 45, vynulovani; boolean debug = 0, i; Tasker tasker; RCSwitch mySwitch = RCSwitch(); void change() { if (stav > 1) { vynulovani++; if (vynulovani >= 30) { vynulovani = 0; stav = 1; tasker.cancel(polocas); tasker.cancel(blinking, 0); tasker.cancel(blinking, delka); tasker.cancel(blinking, 2*delka); minuta = 0; } } else { if (delka == 45) { delka = 35; display(delka); } else if (delka == 35) { delka = 30; display(delka); } else if (delka == 30) { delka = 45; display(delka); } delay(500); } } void enter() { if (stav == 1) { stav = 2; // Ready to start tasker.setInterval(blinking, 500, 0); blinking(0); delay(3000); } else if (stav == 2) { tasker.cancel(blinking, 0); stav = 3; // Poločas 1 display(0); tasker.setInterval(polocas, 60000); } else if (stav == 4) { tasker.cancel(blinking, minuta); stav = 5; //Poločas 2 display(minuta); tasker.setInterval(polocas, 60000); } } void minutym(){ if((stav == 3 && minuta > 0) || (stav == 5 && minuta > delka)){ minuta--; display(minuta); delay(500); } } void minutyp(){ if((stav == 3 && minuta < delka) || (stav == 5 && minuta < 2*delka)){ minuta++; display(minuta); delay(500); } } void polocas() { minuta++; display(minuta); if (minuta == delka && stav == 3) { stav = 4; tasker.cancel(polocas); tasker.setInterval(blinking, 500, minuta); }else if(minuta == 2*delka && stav == 5){ stav = 6; tasker.cancel(polocas); tasker.setInterval(blinking, 500, minuta); } } void setup() { if(debug){ Serial.begin(9600); } mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2 pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(A0, OUTPUT); pinMode(A1, OUTPUT); pinMode(A2, OUTPUT); //Test zobrazení display(88); if(!debug){ delay(60000); } //88 na začátku //tasker.setInterval(display, 500); stav = 1; display(delka); } void loop() { tasker.loop(); if (mySwitch.available()) { long value = mySwitch.getReceivedValue(); if (value == 5587916 || value == 1377740) { change(); } else if (value == 5587772 || value == 1377596) { enter(); } else if (value == 5587952 || value == 1377776) { minutym(); } else if (value == 5587724 || value == 1377548) { minutyp(); } mySwitch.resetAvailable(); } } void blinking(int dig) { if(!i){ digitalWrite(12, 1); digitalWrite(10, 1); digitalWrite(9, 1); digitalWrite(11, 1); digitalWrite(A1, 1); digitalWrite(13, 1); digitalWrite(A0, 1); digitalWrite(A2, 1); if(debug){ Serial.println("blank"); } i=1; }else{ display(dig); i=0; } } void display(int dig) { boolean minuta1[4], minuta2[4]; int_to_bin_digit(dig / 10, minuta1); int_to_bin_digit(dig % 10, minuta2); digitalWrite(12, minuta1[3]); digitalWrite(10, minuta1[2]); digitalWrite(9, minuta1[1]); digitalWrite(11, minuta1[0]); digitalWrite(A1, minuta2[0]); digitalWrite(13, minuta2[1]); digitalWrite(A0, minuta2[2]); digitalWrite(A2, minuta2[3]); if(debug){ Serial.println(dig); } } void int_to_bin_digit(unsigned int in, boolean* out) { /* assert: count <= sizeof(int)*CHAR_BIT */ unsigned int mask = 1U << 3; int i; for (i = 0; i < 4; i++) { out[i] = (in & mask) ? 1 : 0; in <<= 1; } }