-
Notifications
You must be signed in to change notification settings - Fork 0
/
draper_opener.ino
43 lines (38 loc) · 1.19 KB
/
draper_opener.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
int rfPin = 7; // Pin where RF receiver data pin is connected
int stepPin = 8; // Pin connected to STEP on DRV8825
int dirPin = 9; // Pin connected to DIR on DRV8825
bool previousState = LOW; // Previous state of the RF button, default to LOW
bool upOrDown = true; // Previous direction
void setup() {
pinMode(rfPin, INPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
Serial.begin(9600); // Start serial communication
}
void loop() {
bool currentState = digitalRead(rfPin);
if(currentState != previousState) { // Check if state has changed
if(currentState == HIGH) {
Serial.println("Button Pressed");
}
else {
Serial.println("Button Released");
}
previousState = currentState; // Update the previous state
}
if(currentState == HIGH) {
if(upOrDown == true){
digitalWrite(dirPin, HIGH); // Rotate in one direction
}
else {
digitalWrite(dirPin, LOW); // Rotate in the opposite direction
}
digitalWrite(stepPin, HIGH); // Make a step
delay(1);
digitalWrite(stepPin, LOW); // Turn off step
delay(1);
}
else {
// When button is released, stop the motor by not sending any step pulses
}
}