75 lines
1.4 KiB
Plaintext
75 lines
1.4 KiB
Plaintext
|
byte val = 0;
|
||
|
byte val2 = 0;
|
||
|
|
||
|
byte cab=0;
|
||
|
byte command=0;
|
||
|
byte dat=0;
|
||
|
|
||
|
int count=0;
|
||
|
int countr=0;
|
||
|
int N=100;
|
||
|
|
||
|
int RSSI=23;
|
||
|
int CTS=22;
|
||
|
|
||
|
void setup()
|
||
|
{
|
||
|
Serial.begin(9600);
|
||
|
Serial2.begin(9600);
|
||
|
pinMode(RSSI, INPUT);
|
||
|
pinMode(CTS, INPUT);
|
||
|
delay(100);
|
||
|
}
|
||
|
|
||
|
void loop()
|
||
|
{
|
||
|
if (Serial.available()) {
|
||
|
val = Serial.read();
|
||
|
if (val==0xF0)
|
||
|
{
|
||
|
count=1;
|
||
|
cab=val;
|
||
|
}
|
||
|
else if (count==1)
|
||
|
{
|
||
|
count=2;
|
||
|
command=val;
|
||
|
}
|
||
|
else if (count==2)
|
||
|
{
|
||
|
count=3;
|
||
|
dat=val;
|
||
|
}
|
||
|
}
|
||
|
if (count==3)
|
||
|
{
|
||
|
count=0;
|
||
|
while(digitalRead(CTS));
|
||
|
Serial2.print(cab, BYTE);
|
||
|
while(digitalRead(CTS));
|
||
|
Serial2.print(command, BYTE);
|
||
|
while(digitalRead(CTS));
|
||
|
Serial2.print(dat, BYTE);
|
||
|
/*while (!Serial2.available()&&countr<=N)
|
||
|
{
|
||
|
if (countr==N)
|
||
|
{
|
||
|
while(digitalRead(CTS));
|
||
|
Serial2.print(cab, BYTE);
|
||
|
Serial2.print(command, BYTE);
|
||
|
Serial2.print(dat, BYTE);
|
||
|
countr=0;
|
||
|
}
|
||
|
countr=countr+1;
|
||
|
}
|
||
|
countr=0;
|
||
|
while (Serial2.available()) Serial2.flush();
|
||
|
/*while (Serial2.available()&&(countr<2))
|
||
|
{
|
||
|
countr=countr+1;
|
||
|
}
|
||
|
countr=0;*/
|
||
|
}
|
||
|
}
|
||
|
|