//======================================================================================================== // Simple example of alive character sent to a BT receiver // Date 08/05/20220 // Rev. 0 //======================================================================================================== // Arduino UNO board // Serial line toward PC for debugging purposes // SoftwareSerial used to exchange data toward the BT (MIT AI2 code for the phone App) // The circuit: // RX is digital pin 2 (connect to TX of other device) // TX is digital pin 3 (connect to RX of other device) // it is supposed thet the HC05 (or HC06)shield is programmed with 9600 baud toward the Arduino // (sometimes, by default, they are programmed @38400 : check before setting the myserial baudrate) // The alive character shall be sent with a trailing CRLF characters pair, using a println(), because // the MIT AI2 code requires a LF terminator //======================================================================================================== #include #define REFRESH 2000 #define RX 2 #define TX 3 SoftwareSerial myserial(RX,TX); unsigned long parte = 0; void setup(){ Serial.begin(9600); myserial.begin(9600); parte = millis(); } void loop() { DoMyStuff(); if ((millis() - parte) >= (unsigned long)REFRESH) // elapsed 2 seconds, then sends a $ to the phone (alive character) { parte = millis(); // restarts the alive timer ToThePhone('$'); // alive to the phone } } ///////////////////////// Functions ///////////////////////////////// void ToThePhone(char charaliv) // Sends the alive { Serial.println(charaliv); // for debug purposes only, to be commented out when done myserial.println(charaliv); // sends the alive char to the phone by the BT line } //========================================================================================== // mainn functions performed in the loop() void DoMyStuff() {}