-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·88 lines (78 loc) · 2.47 KB
/
main.cpp
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
// #include <Arduino.h>
// #include <stdio.h>
// const int moistureSensor0 = A3;
// const int moistureSensor1 = A4;
// const int moistureSensor2 = A5;
// const int moistureSensor3 = A6;
// const int moistureSensor4 = A7;
// const int power0 = 3;
// const int power1 = 2;
// void setup() {
// Serial.begin(9600);
// pinMode(power0, OUTPUT);
// pinMode(power1, OUTPUT);
// }
// void loop() {
// digitalWrite(power0, HIGH);
// digitalWrite(power1, HIGH);
// delay(1000);
// int sensorValue0 = analogRead(moistureSensor0);
// int sensorValue1 = analogRead(moistureSensor1);
// int sensorValue2 = analogRead(moistureSensor2);
// int sensorValue3 = analogRead(moistureSensor3);
// int sensorValue4 = analogRead(moistureSensor4);
// delay(1000);
// float percentage0 = (1024.0f-sensorValue0)/10.24;
// float percentage1 = (1024.0f-sensorValue1)/10.24;
// float percentage2 = (1024.0f-sensorValue2)/10.24;
// float percentage3 = (1024.0f-sensorValue3)/10.24;
// float percentage4 = (1024.0f-sensorValue4)/10.24;
// digitalWrite(power0, LOW);
// digitalWrite(power1, LOW);
// Serial.println("p " + String(percentage0, 6));
// delay(1000);
// Serial.println("cl " + String(percentage1, 6));
// delay(1000);
// Serial.println("pr " + String(percentage2, 6));
// delay(1000);
// Serial.println("cr " + String(percentage3, 6));
// delay(1000);
// Serial.println("pl " + String(percentage4, 6));
// delay(1800000);
// }
#include <Arduino.h>
#include <stdio.h>
const int moistureSensor0 = A5;
const int moistureSensor1 = A6;
const int moistureSensor2 = A7;
const int power0 = 4;
const int power1 = 3;
const int power2 = 2;
void setup() {
Serial.begin(9600);
pinMode(power0, OUTPUT);
pinMode(power1, OUTPUT);
pinMode(power2, OUTPUT);
}
void loop() {
digitalWrite(power0, HIGH);
digitalWrite(power1, HIGH);
digitalWrite(power2, HIGH);
delay(1000);
int sensorValue0 = analogRead(moistureSensor0);
int sensorValue1 = analogRead(moistureSensor1);
int sensorValue2 = analogRead(moistureSensor2);
delay(1000);
float percentage0 = (1024.0f-sensorValue0)/10.24;
float percentage1 = (1024.0f-sensorValue1)/10.24;
float percentage2 = (1024.0f-sensorValue2)/10.24;
digitalWrite(power0, LOW);
digitalWrite(power1, LOW);
digitalWrite(power2, LOW);
Serial.println("fpl " + String(percentage0, 6));
delay(1000);
Serial.println("fpr " + String(percentage1, 6));
delay(1000);
Serial.println("fc " + String(percentage2, 6));
delay(1800000);
}