/*
Forum: https://forum.arduino.cc/t/display-hinzufugen-status-an-oder-aus/1347226/1
Wokwi: https://wokwi.com/projects/421173630153294849
*/
int LED_pin = 8; // built-in LED
int BUTTON_ON_pin = 7; // Pin 7
int BUTTON_OFF_pin = 4; // Pin 4
// Serial Tx: Pin 20
// Serial Rx: Pin 21
unsigned char command_on[] = { 0x68, 0x40, 0xBF, 0x68, 0x04, 0x03, 0xD3, 0x3D, 0x3C, 0x22, 0x16 };
unsigned char command_off[] = { 0x68, 0x40, 0xBF, 0x68, 0x04, 0x03, 0xD3, 0x3D, 0x35, 0x1B, 0x16 };
void setup()
{
Serial.begin(9600, SERIAL_8E1); // 9600 Baud Even Parity
pinMode(LED_pin, OUTPUT);
digitalWrite(LED_pin, LOW); // LED off
pinMode(BUTTON_ON_pin, INPUT_PULLUP);
pinMode(BUTTON_OFF_pin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(BUTTON_ON_pin) == LOW)
{
digitalWrite(LED_pin, HIGH); // LED on
Serial.write(command_on, sizeof(command_on));
delay(1000); // 1000 ms (just for debounce and sending only once)
digitalWrite(LED_pin, LOW); // LED off
}
else if (digitalRead(BUTTON_OFF_pin) == LOW)
{
digitalWrite(LED_pin, HIGH); // LED on
Serial.write(command_off, sizeof(command_off));
delay(1000); // 1000 ms (just for debounce and sending only once)
digitalWrite(LED_pin, LOW); // LED off
}
}