This week our task was to write an application that interfaces with an input and/or output device that you made, comparing as many tool options as possible". I decided to write an application for switching on an LED using bluetooth.
To begin, I listed the main parts of the user interface I wanted:
The Codes Used
#include "SoftwareSerial.h"
const int LED = A1; // this is physical pin 7, connect wire as sensor
const int Rx = 3; // this is physical pin 2
const int Tx = 4; // this is physical pin 3
SoftwareSerial mySerial(Rx, Tx);
char data = 0;
void setup()
{
pinMode(Rx, INPUT);
pinMode(Tx, OUTPUT);
pinMode(LED, OUTPUT);
mySerial.begin(9600); // send serial data at 9600 bits/sec
}
void loop()
{
if(mySerial.available() > 0) // Send data only when you receive data:
{
data = mySerial.read(); //Read the incoming data & store into data
if(data == '1') // Checks whether value of data is equal to 1
digitalWrite(A1, HIGH); //If value is 1 then LED turns ON
else if(data == '0') // Checks whether value of data is equal to 0
digitalWrite(A1, LOW); //If value is 0 then LED turns OFF
}
}