You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

116 lines
2.3 KiB
C++

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
// V konečné verzi zruším čísla pinů jako proměnné, a debug.
int D1 = 3;
int D2 = 5;
int D4 = 6;
int D8 = 4;
int Dj = 7;
int H1 = 8;
int H2 = 10;
int H4 = 11;
int H8 = 9;
int Hj = 12;
boolean debug = 0;
int domaci;
int hoste;
void setup() {
if(debug){ Serial.begin(9600); }
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D8, OUTPUT);
pinMode(Dj, OUTPUT);
pinMode(H1, OUTPUT);
pinMode(H2, OUTPUT);
pinMode(H4, OUTPUT);
pinMode(H8, OUTPUT);
pinMode(Hj, OUTPUT);
//Test zobrazení
domaci = 18;
hoste = 18;
display();
if(!debug){ delay(60000); }
domaci = 0;
hoste = 0;
display();
}
void loop() {
if (mySwitch.available()) {
long value = mySwitch.getReceivedValue();
if(value == 5587904 || value == 1377728){
domaci += 1;
if (domaci == 10) {
domaci = 0;
}
display(); delay(1000);
}else if(value == 5587760 || value==1377584){
hoste += 1;
if (hoste == 10) {
hoste = 0;
}
display(); delay(1000);
}
mySwitch.resetAvailable();
}
}
void display() {
boolean domaci_b[4], hoste_b[4];
int_to_bin_digit(domaci % 10, domaci_b);
int_to_bin_digit(hoste % 10, hoste_b);
digitalWrite(D1, domaci_b[3]);
digitalWrite(D2, domaci_b[2]);
digitalWrite(D4, domaci_b[1]);
digitalWrite(D8, domaci_b[0]);
digitalWrite(Dj, domaci/10);
digitalWrite(H1, hoste_b[3]);
digitalWrite(H2, hoste_b[2]);
digitalWrite(H4, hoste_b[1]);
digitalWrite(H8, hoste_b[0]);
digitalWrite(Hj, hoste/10);
if(debug){
Serial.print(domaci); Serial.print("\t:\t"); Serial.println(hoste);
Serial.print(domaci/10);
Serial.print(" ");
Serial.print(domaci_b[0]);
Serial.print(domaci_b[1]);
Serial.print(domaci_b[2]);
Serial.print(domaci_b[3]);
Serial.print("\t:\t");
Serial.print(hoste/10);
Serial.print(" ");
Serial.print(hoste_b[0]);
Serial.print(hoste_b[1]);
Serial.print(hoste_b[2]);
Serial.println(hoste_b[3]);
}
}
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;
}
}