What I am trying to do is to get a stepper motor to read an input from an IR sensor and turn either left or right. I got the code to wrok using a switch statement from earlier, but the problem was this:
When a button was pressed, it ran the code all the way through. What I need is a way to break the loop if a new button is pressed. We have three buttons, one to turn the motor to the left, one to turn the motor to the right and one to stop the motor. We managed to get the hex and decimal versions of the buttons. The error I get is this:
StepperPractice.cpp:34:9: error: invalid suffix "Received" on integer constant
I get it for all three If statements even though I commented out some of it. Any idea why it is wrong?
#include <IRremote.h>
#define button1 16582903
#define button2 16615543
#define button3 16599223
#define RECV_PIN 10
IRrecv irrecv(RECV_PIN);
decode_results results;
long lReceived = 0 ;
#define DIR_PIN 2
#define STEP_PIN 3
void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode(RECV_PIN , INPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop(){
if (irrecv.decode(&results)) {
lReceived = results.value ;
if (1Received == button1){
digitalWrite (STEP_PIN, HIGH);
digitalWrite (DIR_PIN, HIGH);
//rotate a specific number of degrees
rotateDeg(3600, .5);
delay(1000);
}
// if (1Received == button2){
// digitalWrite(STEP_PIN, LOW);
// digitalWrite( DIR_PIN, HIGH);
// }
// if (1Received == button3){
// digitalWrite( STEP_PIN, HIGH);
// digitalWrite( DIR_PIN, LOW);
// rotateDeg(-3600, .5); //reverse
// delay(1000);
// }
irrecv.resume(); // Receive the next value
}
}
void rotateDeg(float deg, float speed){
//rotate a specific number of degrees (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (deg > 0)? HIGH:LOW;
digitalWrite(DIR_PIN,dir);
int steps = abs(deg)*(1/0.225);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}