/* AUTHOR: Jon Edison DATE: Nov 6 2015 LICENSE: Public domain (use at your own risk) CONTACT: jon at nymrsc org uk */ #include const int rxpin = 2; const int txpin = 3; SoftwareSerial serial_timer(rxpin,txpin); const int buttonPin = 4; // the pin that the pushbutton is attached to // Variables: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button char incomingByte = 0; // Input from Timer char inByte = 0; // Input from USB void setup() { // initialize the button pin as a input: pinMode(buttonPin, INPUT); // initialize serial communication: Serial.begin(2400); serial_timer.begin(2400); } void loop() { // read the pushbutton input pin: buttonState = digitalRead(buttonPin); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed if (buttonState == LOW) { // if current state is LOW then button // went from on to off: // increment the counter // buttonPushCounter++; Serial.println(); Serial.println("S\n"); // S for for "Start" when Button pressed } } // Update Button Status lastButtonState = buttonState; // send data only when you receive data: if (Serial.available() > 0) { inByte = Serial.read(); // char serial_timer.println(inByte); } if (inByte == 86 ) { // Display Version No if "V" is sent Serial.println("sketch_nov6e 16/11/2015"); // Make sure the Serial Monitor sends at least a New Line // otherwise this will print forever!! } // Delay a little bit to avoid bouncing delay(50); if (serial_timer.available() > 0) { // read the incoming byte from Timer: char incomingByte = serial_timer.read(); // say what you got on USB: Serial.write(incomingByte); } }