-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiplexTxSync.ino
70 lines (61 loc) · 1.34 KB
/
multiplexTxSync.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// definizione dei pin di ciascun segmento TX
#define NSTEP 10000
#define TBASE 125
unsigned long tbase = TBASE;
unsigned long prec = 0;
byte btn1 = 4;
byte btn2 = 5;
byte btn3 = 6;
byte btn4 = 7;
unsigned long step=0;
byte slots[4];
byte dataport = 3;
byte syncport = 2;
byte i;
void setup()
{
Serial.begin(19200);
pinMode(btn1, INPUT);
pinMode(btn2, INPUT);
pinMode(btn3, INPUT);
pinMode(btn4, INPUT);
pinMode(syncport, OUTPUT);
pinMode(dataport, OUTPUT);
i=0;
}
void doFrame(){
//legge valore attuale dell'ingresso
slots[0] = digitalRead(btn1);
slots[1] = digitalRead(btn2);
slots[2] = digitalRead(btn3);
slots[3] = digitalRead(btn4);
}
void printFrame(){
Serial.println("Frame corrente: ");
for(int ii=0;ii<4;ii++){
Serial.print(slots[ii]);
Serial.print(", ");
}
Serial.println();
Serial.println("----------------------------------");
}
void loop()
{
if((millis()-prec) > tbase) //schedulatore
{
prec = millis();
step = (step + 1) % NSTEP;
if(!(step%2)){
doFrame();
digitalWrite(dataport, slots[i]);
digitalWrite(syncport, HIGH);
i++;
if(i > 3){ // fine cifra (trama)
i = 0;
printFrame();
}
}else{
digitalWrite(syncport, LOW); // ripristina passaggio per lo zero (generazione del clock)
}
}
}