Hi All,
I am new to this and trying to learn all I can, so I apologize for my lack of knowledge!! Any help or advise would be greatly appreciated!
Anyway, I am working to add a stepper motor to my blinds to control the up and down movement. I have code the works but it is not doing what I need and I am not sure how to handle it. Ideally I would like three specific positions for the blinds: Open, Closed and Half Open. To make it similar I have commented the Half Open code out and I am focusing on Open and Close.
My first issue is with my if statements, I get "exit status 1 lvalue required as left operand of assignment". I added two variables Open and Closed to identify the position of the blinds. Before the setup loop I declared them and gave a value of 0 = Open and 1 = Closed. This is so I can change these when the code runs and so the blind doesn't try to open when it is already open. I tried == and = and either work and I still get this same error. If I take out the last two arguments it works no problem.
If anyone can help me out with this error and if you have any advise or comments on how to better handle this I would be GREATLY APPRECIATED!! Thanks in advance!
Thanks,
Brian
//Libraries to Include
#include <Stepper.h>
//Variables, Pins
#define STEPS 32 //Number of steps per revolution of internal shaft
int Steps2Take; // 2048 = 1 Revolution;
int Open = 0;
int Closed = 1;
//int HalfOpen = 0 ;
//Declare objects
//In1, In2, In3, In4 in the sequence 1-3-2-4
//initialize the stepper library on pins 8 through 11:
Stepper myStepper(STEPS, 8, 10, 9, 11);
void setup() {
//Start Serial Connection
Serial.begin(9600);
//Configure Pins
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
//pinMode(4, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
//pinMode(7, OUTPUT);
}
void loop() {
//Read the pushbutton value into a varible
int sensorVal1 = digitalRead(2);
int sensorVal2 = digitalRead(3);
//int sensorVal3 = digitalRead(4);
//Print the sensor values
Serial.println(Open);
Serial.println("Open value");
Serial.println(Closed);
Serial.println("Closed value");
//Serial.println(HalfOpen);
Serial.println(sensorVal1);
Serial.println(" - S1, ");
Serial.println(sensorVal2);
Serial.println(" - S2, ");
//Serial.println(sensorVal3);
//Serial.println(" - S3, ");
if (sensorVal1 == 0 && sensorVal2 == 1 && Open = 0 && Closed = 1){
digitalWrite(5, HIGH);
Serial.print("Blinds OPENING CW, ");
//Set the speed at 500 rpm(max):
myStepper.setSpeed(500);
//Set Steps2Take at one revolution (2048 steps)
Steps2Take = 2048;
//Tell stepper to rotate CW the number of steps = Steps2Take
myStepper.step(Steps2Take);
Open = 1;
Closed = 0;
Serial.print("Blinds OPENED, ");
delay(1000);
}
if (sensorVal2 == 0 && sensorVal1 == 1 && Open = 1 && Closed = 0){
digitalWrite(6, HIGH);
Serial.print("Blinds Closing CCW, ");
//Set the speed at 500 rpm(max):
myStepper.setSpeed(500);
//Set Steps2Take at one revolution (2048 steps)
Steps2Take = -2048;
//Tell stepper to rotate CW the number of steps = Steps2Take
myStepper.step(Steps2Take);
Closed = 1;
Open = 0;
Serial.print("Blinds Closed CCW, ");
delay(1000);
}
//if (sensorVal3 == 0 && sensorVal1 == 1 && sensorVal2 == 1){
//digitalWrite(7, HIGH);
//Serial.print("Blinds to HALF OPEN CW, ");
//Set the speed at 500 rpm(max):
//myStepper.setSpeed(500);
//Set Steps2Take at one revolution (2048 steps)
//Steps2Take = 1024;
//Tell stepper to rotate CW the number of steps = Steps2Take
//myStepper.step(Steps2Take);
//Serial.print("Blinds HALF OPENED, ");
//delay(1000);
//}
}
Stepper_Motor_with_three_buttons.ino (2.44 KB)