-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlLamp.ino
54 lines (46 loc) · 843 Bytes
/
ControlLamp.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
52
53
54
#include <SoftwareSerial.h>
#include <Servo.h>
Servo servo;
void turnSwtich();
int blueTx=2;
int blueRx=3;
SoftwareSerial mySerial(blueTx, blueRx);
String myString="";
int angle = 90;
void setup() {
mySerial.begin(9600);
}
void loop() {
while(mySerial.available())
{
char myChar = (char)mySerial.read();
myString+=myChar;
delay(5);
servo.attach(5);
servo.write(90);
pinMode(LED_BUILTIN, OUTPUT);
}
if(!myString.equals(""))
{
Serial.println("input value: "+myString);
if(myString=="switch")
{
turnSwitch();
}
else {
}
myString="";
}
}
void turnSwitch() {
static bool isOn = true;
if (isOn) {
servo.writeMicroseconds(1700);
isOn = false;
} else {
servo.writeMicroseconds(1200);
isOn = true;
}
delay(400);
servo.detach();
}