byte switchPin = 2; // Switch connected to pin 2
byte sendByte[] = {0x55, 0x56, 0x00, 0x00, 0x00, 0x03, 0x01, 0xAF};
//-------------------------------------------------------------------
void setup() {
pinMode(switchPin, INPUT_PULLUP); // Set pin 2 as an input
Serial1.begin(9600); // Start serial communication at 9600 bps
Serial.begin(115200);
}
//-------------------------------------------------------------------
void loop() {
if (digitalRead(switchPin) == LOW) { // If switch is ON,
delay(30);
if (digitalRead(switchPin) == LOW) {
for (int i = 0; i < 8; i++)
{
Serial1.print(sendByte[i], HEX); // send 1 to Serial (Processing)
Serial.print(sendByte[i], HEX);
}
}
while (digitalRead(switchPin) == LOW) {}
Serial.println(" ");
}
}