-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blink.ino
114 lines (98 loc) · 3.96 KB
/
Blink.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#define solenoidValve1Pin A0
#define solenoidValve2Pin A1
#define mosfetSwitchPin A4
#define pressureSensor1Pin A10
#define pressureSensor2Pin A5
#define builtInLedPin PC13 // Assuming STM32 board has an LED_BUILTIN constant
void setup() {
pinMode(solenoidValve1Pin, OUTPUT);
pinMode(solenoidValve2Pin, OUTPUT);
pinMode(mosfetSwitchPin, OUTPUT);
pinMode(builtInLedPin, OUTPUT);
//digitalWrite(solenoidValve1Pin, HIGH);
// Add setup for pressure sensors if needed
//delay(1500);
digitalWrite(builtInLedPin, LOW);
sequenceControl(15000, 1000);
// Turn off built-in LED once setup is complete
digitalWrite(builtInLedPin, HIGH);
}
void loop() {
// Your main loop code here
/*
// Read pressure values
int pressure1 = readPressure(pressureSensor1Pin);
int pressure2 = readPressure(pressureSensor2Pin);
// Check if both pressures are within the specified range
if (pressure1 >= 6000 && pressure1 <= 6500 && pressure2 >= 6000 && pressure2 <= 6500) {
// Perform your sequence control or other actions here
sequenceControl(1000, 2);
}*/
}
void sequenceControl(int timeDelay, int frequency) {
//digitalWrite(builtInLedPin, HIGH); // Turn on built-in LED
delay(timeDelay);
digitalWrite(solenoidValve1Pin, HIGH);
digitalWrite(solenoidValve2Pin, HIGH);
// Calculate the loop count for a 1.5-second duration
int loopCount = static_cast<int>((1500000.0 / (1000000.0 / frequency)));
for (int i = 0; i < loopCount; i++) {
digitalWrite(mosfetSwitchPin, LOW);
digitalWrite(builtInLedPin, LOW); // Turn on built-in LED
delayMicroseconds(500000 / frequency);
digitalWrite(mosfetSwitchPin, HIGH);
digitalWrite(builtInLedPin, HIGH); // Turn off built-in LED
delayMicroseconds(500000 / frequency);
}
/*
// Calculate the loop count for a 1.5-second duration
loopCount = static_cast<int>((1500000.0 / (1000000.0 / (frequency/2))));
delay(1000);
for (int i = 0; i < loopCount; i++) {
digitalWrite(mosfetSwitchPin, HIGH);
digitalWrite(builtInLedPin, HIGH); // Turn on built-in LED
delayMicroseconds(500000 / (frequency/2));
digitalWrite(mosfetSwitchPin, LOW);
digitalWrite(builtInLedPin, LOW); // Turn off built-in LED
delayMicroseconds(500000 / (frequency/2));
}
// Calculate the loop count for a 1.5-second duration
loopCount = static_cast<int>((1500000.0 / (1000000.0 / (frequency/4))));
delay(1000);
for (int i = 0; i < loopCount; i++) {
digitalWrite(mosfetSwitchPin, HIGH);
digitalWrite(builtInLedPin, HIGH); // Turn on built-in LED
delayMicroseconds(500000 / (frequency/4));
digitalWrite(mosfetSwitchPin, LOW);
digitalWrite(builtInLedPin, LOW); // Turn off built-in LED
delayMicroseconds(500000 / (frequency/4));
}
// Calculate the loop count for a 1.5-second duration
loopCount = static_cast<int>((1500000.0 / (1000000.0 / (frequency/8))));
delay(1000);
for (int i = 0; i < loopCount; i++) {
digitalWrite(mosfetSwitchPin, HIGH);
digitalWrite(builtInLedPin, HIGH); // Turn on built-in LED
delayMicroseconds(500000 / (frequency/8));
digitalWrite(mosfetSwitchPin, LOW);
digitalWrite(builtInLedPin, LOW); // Turn off built-in LED
delayMicroseconds(500000 / (frequency/8));
}
// Calculate the loop count for a 1.5-second duration
loopCount = static_cast<int>((1500000.0 / (1000000.0 / (frequency/16))));
delay(1000);
for (int i = 0; i < loopCount; i++) {
digitalWrite(mosfetSwitchPin, HIGH);
digitalWrite(builtInLedPin, HIGH); // Turn on built-in LED
delayMicroseconds(500000 / (frequency/16));
digitalWrite(mosfetSwitchPin, LOW);
digitalWrite(builtInLedPin, LOW); // Turn off built-in LED
delayMicroseconds(500000 / (frequency/16));
}
*/
delay(2000);
digitalWrite(solenoidValve1Pin, LOW);
digitalWrite(solenoidValve2Pin, LOW);
// Turn off built-in LED once setup is complete
digitalWrite(builtInLedPin, LOW);
}