Hello,
It's my first time using a forum, hope I do ok.
Ok, so my Arduino setup has 2 stepper motors which I am controlling with an infrared remote.
I've coded the motors in a loop so that one motor moves one step, then the 2nd moves another step, until both motors have made one full revolution, like so...
for (int i=0; i<2048; i++){ // Set loop for 2 motors each rotating 1 full circle clockwise
small_stepper1.setSpeed(500); //Max seems to be 700
small_stepper2.setSpeed(500); //Max seems to be 700
Steps2Take = 1; // Rotate CW
small_stepper1.step(Steps2Take);
small_stepper2.step(Steps2Take);
delay(1);
}
I've coded the motor's to revolve clockwise when I press one button and anti-clockwise when I press the another button.
I'm now trying and failing to insert a 3rd button press which stops the motors before the full rotation. For example, something like this...
for (int i=0; i<2048; i++){ // Set loop for 2 motors each rotating 1 full circle clockwise
small_stepper1.setSpeed(500); //Max seems to be 700
small_stepper2.setSpeed(500); //Max seems to be 700
Steps2Take = 1; // Rotate CW
small_stepper1.step(Steps2Take);
small_stepper2.step(Steps2Take);
delay(1);
irrecv.decode(&results);
if (results.value == 0xFF18E7) {
i = 2048;
}
}
break;
As you might be able to tell, I'm not that used to IR programming code at the mo! Hope one of you can help. Many thanks. Here's the full code...
#include "Stepper.h"
#include "IRremote.h"
/*----- Variables, Pins -----*/
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 9; // Signal Pin of IR receiver to Arduino Digital Pin 6
/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4
// In5, In6, In7, In7 in the sequence 5-7-6-8
Stepper small_stepper1(STEPS, 5, 7, 6, 8);
Stepper small_stepper2(STEPS, 1, 3, 2, 4);
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup()
{
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch(results.value)
{
case 0xFF30CF: // Button 1 pressed
for (int i=0; i<2048; i++){ // Set loop for 2 motors each rotating 1 full circle clockwise
small_stepper1.setSpeed(500); //Max seems to be 700
small_stepper2.setSpeed(500); //Max seems to be 700
Steps2Take = 1; // Rotate CW
small_stepper1.step(Steps2Take);
small_stepper2.step(Steps2Take);
delay(1);
}
break;
case 0xFF7A85: // Button 2 pressed
for (int i=0; i>-2048; i--){ // Set loop for 2 motors each rotating 1 full circle anti-clockwise
small_stepper1.setSpeed(500); //Max seems to be 700
small_stepper2.setSpeed(500); //Max seems to be 700
Steps2Take = -1; // Rotate CCW
small_stepper1.step(Steps2Take);
small_stepper2.step(Steps2Take);
delay(1);
}
break;
}
irrecv.resume(); // receive the next value
}
}/* --end main loop -- */