#include // constants won't change. They're used here to // set pin numbers: const int buttonPin = 7; // the number of the pushbutton pin const int ledPin = 8; // the number of the LED pin SoftwareSerial mySerial(0, 1); // RX, TX void setup() { mySerial.begin(115200); pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } int NOTHING = 0; int ZOOM_IN = 97; int ZOOM_OUT = 115; int BLOCK_TIME = 500; int DEBOUNCE_TIME = 125; int OFF = 0; int CLICK = 1; int HOLD = 2; int state = OFF; int ledState = HIGH; int command = NOTHING; void loop() { // read the state of the switch into a local variable: int reading = digitalRead(buttonPin); //button pressed if (reading == LOW) { delay(DEBOUNCE_TIME); reading = digitalRead(buttonPin); // released if (reading == HIGH) { if (state == OFF) { state = CLICK; mySerial.write(state); } else { state = OFF; mySerial.write(NOTHING); } } else { if (state == CLICK) { state = HOLD; mySerial.write(ZOOM_OUT); command = ZOOM_OUT; } else if (state == OFF) { state = HOLD; mySerial.write(ZOOM_IN); command = ZOOM_IN; } else { mySerial.write(command); } } } } void switchLed() { if (ledState == HIGH) { ledState = LOW; } else { ledState = HIGH; } digitalWrite(ledPin, ledState); }