/* Software serial multple serial test Receives from the hardware serial, sends to software serial. Receives from software serial, sends to hardware serial. The circuit: * RX is digital pin 10 (connect to TX of other device) * TX is digital pin 11 (connect to RX of other device) Note: Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). created back in the mists of time modified 25 May 2012 by Tom Igoe based on Mikal Hart's example modified 9 months ago by Dorota Orlof modified 19 March 2019 by Pamela Martello This example code is in the public domain. */ #include SoftwareSerial mySerial(0, 1); // RX, TX bool buttonDown = false; int inPin = 3; // the number of the input pin int outPin = 7; // the number of the output pin int state = LOW; // the current state of the output pin int reading; // the current reading from the input pin int previous = HIGH; // the previous reading from the input pin // the follow variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long time = 0; // the last time the output pin was toggled long debounce = 150; // the debounce time, increase if the output flickers void setup() { mySerial.begin(9600); mySerial.println("something"); pinMode(inPin, INPUT); pinMode(outPin, OUTPUT); } void loop() { bool buttonReleased = digitalRead(inPin); // assign TRUE or FALSE to buttonReleased,button pressed FALSE if button not pressed TRUE. This is a button with a pullup resistor if(buttonReleased){ //if the button isn't pressed buttonDown = false; // button down false } else{ // if the button is pressed the following happen if(!buttonDown){ //if true write "click me" mySerial.println("click me!"); } if (buttonDown==true && millis() - time > debounce) { if (state == HIGH) state = LOW; else state = HIGH; time = millis(); } buttonDown = true; } digitalWrite(outPin, state); if (mySerial.available()) { mySerial.write(mySerial.read()); } // if (mySerial.available()) { // mySerial.write(mySerial.read()); // } // reading = digitalRead(inPin); // if the input just went from LOW and HIGH and we've waited long enough // to ignore any noise on the circuit, toggle the output pin and remember // the time // if (reading == HIGH && previous == LOW && millis() - time > debounce) { // if (buttonDown==true && millis() - time > debounce) { // if (state == HIGH) // state = LOW; // else // state = HIGH; // // time = millis(); // } // // digitalWrite(outPin, state); //previous = reading; }