Hi,
At the beginning I immediately warn that I am a complete amateur.
I got a small positioner that I mechanically made from the laser guide from the old CD
I want to control it using IR - I already have a remote control, I decoded the buttons.
Left / Right I'm allowed to travel, but only a set value in the steps I gave him.
I would like to add features at the beginning
I hold the "A" button - as long as I keep it for so long it goes right with the speed specified in the program
button / "B" - similarly the same to the left
possibly add a ramp that speeds up over time?
Can anyone help?
here is my sketch:
#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 = 6; // 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
Stepper small_stepper(STEPS, 8, 10, 9, 11);
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 0x8C549057: // UP button pressed
small_stepper.setSpeed(500); //Max seems to be 700
Steps2Take = 10; // Rotate CW
small_stepper.step(Steps2Take);
delay(2000);
break;
case 0xDE5526F7: // DOWN button pressed
small_stepper.setSpeed(500);
Steps2Take = -10; // Rotate CCW
small_stepper.step(Steps2Take);
delay(2000);
break;
}
irrecv.resume(); // receive the next value
}
}/* --end main loop -- */
If you HAVE decoded the buttons, you know that the remote sends one code when a button is pressed and released, and two codes when the button is pressed and held. The first code defines what to do. The second code says repeat the previous action.
That second code is the same regardless of which button is pressed.
Given that, it is simple to read each code, and determine if it means do something different or do the last thing again. It is simple to do the different thing or to do the same thing again.
You need to tell us what that program actually does and what you want it to do that is different.
I would be inclined just to move a single step in every iteration and I would not have any delay()s. The standard stepper library blocks the Arduino until it completes all its steps.
If you hold the IR button down how often is a repeat signal sent - how many microseconds between repeats?
actually when i click the remote button it goes 1 revolution each direction
Well, that is clearly not what you want, so change it. Since only you can see the code, only you can change it.
but i want to have movement when i hold left or right button and stop when i stop holding/pressing the button
If the remote sends the "3" code over and over when you press the "3", then step once every time you get the "3" code. Maybe make the "9" code step 2 times, or 5 times, or 10 times.
Have two other switches that single step and multistep the other way.