-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharduinoCode.ino
67 lines (54 loc) · 1.39 KB
/
arduinoCode.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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <Servo.h>
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin1 = 12; // the number of the LED pin
const int ledPin2 = 8;
boolean forward = true;
Servo servo;
int pos = 0;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize the pushbutton pin as an input:
servo.attach(9);
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH
int input;
if(Serial.available()){
input = Serial.read();
if(input > 1) {
// Serial.write("received " + ((char)(input)=='b'));
}
}
if((char)(input) == 'b') {
digitalWrite(ledPin1, HIGH);
} else {
digitalWrite(ledPin1, LOW);
}
if((char)(input) == 'd') {
digitalWrite(ledPin2, HIGH);
} else {
digitalWrite(ledPin2, LOW);
}
if((char)(input) == 'f') {
if(forward) {
servo.write(pos++);
if(pos > 170*2) {
forward = false;
}
} else {
servo.write(pos--);
if(pos < 10/2) {
forward = true;
}
}
}
}