-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino.ino
91 lines (88 loc) · 1.65 KB
/
arduino.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
int wifi=8;
int manual=7;
int load=13;
int load_ip=2;
boolean currentValue,previousValue,wifi_bool;
void setup() {
pinMode(wifi,OUTPUT);
pinMode(manual,INPUT_PULLUP);
pinMode(load,OUTPUT);
pinMode(load_ip,INPUT);
Serial.begin(9600);
}
void loop() {
currentValue=getValue(manual);
//Serial.print(currentValue);
delay(100);
if(Serial.available())
{
int val=Serial.read()-'0';
if(val==1)
{
if(wifi_bool==false)
{
digitalWrite(wifi,HIGH);
wifi_bool=true;
}
else
{
digitalWrite(wifi,LOW);
wifi_bool=false;
}
if(load_fun())
Serial.print("1");
else
Serial.print("0");
}
}
else if(currentValue != previousValue)
{
previousValue=currentValue;
if(load_fun())
Serial.print("1");
else
Serial.print("0");
}
if(digitalRead(load_ip)==HIGH)
digitalWrite(load,HIGH);
else
digitalWrite(load,LOW);
}
boolean getValue(int pin)
{
if(digitalRead(pin)==LOW)
return true;
else
return false;
}
boolean load_fun()
{
if(currentValue && wifi_bool)
{
//Serial.println();
//Serial.print(currentValue);
//Serial.println(wifi_bool);
return true;
}
else if(!currentValue && wifi_bool)
{
//Serial.println();
//Serial.print(currentValue);
//Serial.println(wifi_bool);
return false;
}
else if(currentValue && !wifi_bool)
{
//Serial.println();
//Serial.print(currentValue);
//Serial.println(wifi_bool);
return false;
}
else if(!currentValue && !wifi_bool)
{
//Serial.println();
//Serial.print(currentValue);
//Serial.println(wifi_bool);
return true;
}
}