-
Notifications
You must be signed in to change notification settings - Fork 16
/
ArduinoLight.ino
51 lines (47 loc) · 1.23 KB
/
ArduinoLight.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Include the module so we don't
//have to use the default Serial
//so the Arduino can be plugged in
//to a computer and still use bluetooth
#include <SoftwareSerial.h>
//Define the pins used for receiving
//and transmitting information via Bluetooth
const int rxpin = 2;
const int txpin = 3;
//Variable to store input value
//initialized with arbitrary value
char k = 'A';
//Connect the Bluetooth module
SoftwareSerial bluetooth(rxpin, txpin);
//Define the pin to control the light
int lightbulb = 7
void setup()
{
//Set the lightbulb pin to put power out
pinMode(lightbulb, OUTPUT);
//Initialize Serial for debugging purposes
Serial.begin(9600);
Serial.println("Serial ready");
//Initialize the bluetooth
bluetooth.begin(9600);
bluetooth.println("Bluetooth ready");
}
void loop()
{
//Check for new data
if(bluetooth.available()){
//Remember new data
k = bluetooth.read();
//Print the data for debugging purposes
Serial.println(k);
}
//Turn on the light if transmitted data is H
if( k == 'H' ){
digitalWrite(7, HIGH);
}
//Turn off the light if transmitted data is L
else if( k == 'L') {
digitalWrite(7, LOW);
}
//Wait ten milliseconds to decrease unnecessary hardware strain
delay(10);
}