Riprendo questo topic per chiedere se questo codice è corretto.
int rx=3;
int tx=4;
int dx = 0;
int sx = 1;
int st = 2;
// definizione della struttura
union RTX_b
{
unsigned char toSendByte;
struct PinStato
{
unsigned char Bit1:
1;
unsigned char Bit2:
1;
unsigned char Bit3:
1;
unsigned char Bit4:
1;
unsigned char Bit5:
1;
unsigned char Bit6:
1;
unsigned char Bit7:
1;
unsigned char Bit8:
1;
}
Bits;
} ;
void setup()
{
pinMode(dx, INPUT);
pinMode(sx, INPUT);
pinMode(st, INPUT);
}
void loop() // run over and over
{
union RTX_b RTX_data;
RTX_data.Bits.Bit1 = digitalRead(dx);
RTX_data.Bits.Bit2 = digitalRead(sx);
RTX_data.Bits.Bit3 = digitalRead(st);
}
L'idea sarebbe quella di definire la union a livello globale ed usarla a livello locale.
Grazie