-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitScroll.ino
53 lines (48 loc) · 1.36 KB
/
fitScroll.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
// declare everything.
int ban = 7;
int ban2 = 8;
int led = 13;
int flag1=0;
int flag2=0;
int res=0;
//typical arduino setup
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
//start ban,ban2 as input pins
pinMode(ban, INPUT);
pinMode(ban2, INPUT);
pinMode(led, OUTPUT);//for debugging, will use Arduino's in led.
//turn led off
digitalWrite(led,0);
}
// the loop routine runs over and over again forever:
void loop() {
//read !ed value from the pins
int buttonState = !digitalRead(ban);
int buttonState2 = !digitalRead(ban2);
//if the pin 7 (ban) gets a positive value (the sensor got obstructed)
if(buttonState){
//checks if the sensor for pin 8 was obstructed before
if(flag2){
res=1; //turn led on
flag2=0; //reset flag2
Serial.write('1'); //sends 1, indicating to go up
delay(200); //wait a little
}
else
flag1=1; //this means the pin on this sensor was the first to be obstructed
}
if(buttonState2){
//checks if the sensor for pin 7 was obstructed before
if(flag1){
res=0;//turn led off
flag1=0;//reset value
Serial.write('2'); //sends 2, indicating to go down
delay(200);//waits for next input
}
else
flag2=1;//this means the pin on this sensor was the first to be obstructed
}
digitalWrite(led,res);
}