Created
October 7, 2017 09:45
-
-
Save GeorgiosGoniotakis/1e39a39e12a2aa095fea1ec682b0933d to your computer and use it in GitHub Desktop.
Sketch that tests the functionality of the BluetoothWrapper Android library. It demonstrates a connection between an Arduino board and a Bluetooth module (currently HC-05).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Sketch that tests the functionality of the BluetoothWrapper Android | |
library available here: https://github.com/GeorgiosGoniotakis/BluetoothWrapper | |
It demonstrates a connection between an Arduino board and a | |
Bluetooth module (currently HC-05). | |
author: Georgios Goniotakis | |
date: 07 Oct 2017 | |
version: 1.0.0 | |
*/ | |
#include <SoftwareSerial.h> | |
#define TXD 2 // RXD Pin of the Bluetooth Module | |
#define RXD 3 // TXD Pin of the Bluetooth Module | |
#define LED_PIN 13 // Arduino LED pin | |
#define UPDATE_INTERVAL 1000 // Time interval for sending a serial message | |
SoftwareSerial mySerial(RXD, TXD); // Initialize a new serial channel with the bluetooth module | |
unsigned long previous = 0; | |
void setup() { | |
mySerial.setTimeout(50); | |
mySerial.begin(9600); // Initialize the serial port | |
pinMode(LED_PIN, OUTPUT); // Set the LED pin as output | |
} | |
void loop() { | |
unsigned long current = millis(); | |
/* Transmitting a message to serial output */ | |
if (current - previous >= UPDATE_INTERVAL) { | |
mySerial.println("INPUT STRING"); | |
previous = current; | |
} | |
/* Reading a string from serial input */ | |
if (mySerial.available() > 0) { | |
String input = mySerial.readString(); | |
/* If incoming message equalt to "OPEN" then blink LED | |
Please do not use delay() in your code, this is just | |
for demonstration purposes | |
*/ | |
if (input.equals("OPEN")) { | |
digitalWrite(LED_PIN, HIGH); | |
delay(500); | |
digitalWrite(LED_PIN, LOW); | |
delay(500); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment