-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_digital_pin.ino
64 lines (51 loc) · 1.25 KB
/
read_digital_pin.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
int in = 13;
int in2 = 12;
int reading = 0;
int reading2 = 0;
bool v1 = false;
bool v2 = false;
float sleep = 0.75;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(in,INPUT);
digitalWrite(in,HIGH);
pinMode(in2,INPUT);
digitalWrite(in2,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
reading = digitalRead(in);
if(reading == LOW){
Serial.println("High1");
//delay(sleep);
}
reading2 = digitalRead(in2);
if(reading2 == LOW){
Serial.println("High2");
//delay(sleep);
}
int sensorValue1 = analogRead(A0);
float voltage1 = sensorValue1 * (5.0 / 1023.0);
int sensorValue2 = analogRead(A1);
float voltage2 = sensorValue2 * (5.0 / 1023.0);
if ((voltage1 < 0.6) || (voltage1 > 3)){
Serial.println(String("Y Axis") + voltage1);
v1 = true;
//delay(sleep);
}
else if(v1 == true){
Serial.println(String("Y Axis") + -1);
v1 = false;
}
if((voltage2 < 0.6) || (voltage2 > 3)){
Serial.println(String("X Axis") + voltage2);
v2 = true;
//delay(sleep);
}
else if(v2 == true){
Serial.println(String("X Axis") + -1);
v2 = false;
}
delay(75);
}