There is a code in which the value of “H” is transmitted to the PC’s COM port when the button is pressed, and again when it is pressed “L”. Interested in how to make another event, namely: when you press the button, the value "H" is transmitted to the port, when you press it once - "P", and when you hold the key for one second, the value "L" must be transmitted to the COM port. I post the existing code, tell me, please. If something is not clear, I will explain:
int switchPin = 12; int ledPin = 13; boolean lastBut = LOW; boolean curBut = LOW; boolean ledOn = false; int val=0; void setup() { pinMode (switchPin, INPUT); pinMode (ledPin, OUTPUT); Serial.begin(9600); } boolean debounce(boolean last) { boolean cur=digitalRead(switchPin); if (last!=cur) { delay(5); cur = digitalRead(switchPin); } return cur; } void loop() { curBut=debounce (lastBut); if (lastBut == LOW && curBut == HIGH) { ledOn =!ledOn; } lastBut = curBut; digitalWrite(ledPin,ledOn); if (ledOn == HIGH) { Serial.println("H"); } else { Serial.println("L"); } delay(100); }