Go Down

Topic: Stepper Motor Control with Arcade Joystick (Read 4 times) previous topic - next topic

TheBlommie

Hi Ash

No problem. Take your time with the code. You are my sidekick, hehe. Okay, I think I understood the acii drawing. Have a look at my drawing and tell me if I have it right?

Thanks a mil!

ash901226


TheBlommie

Cool stuff! I'll be waiting for the code and then I'll have to experiment.

Thanks Ash

ash901226

try this one, it can compile.
Code: [Select]
#include <Bounce.h>
#include <Stepper.h>
const int num_step = 50; // motor steps per revolution
const int pwm_cha = 3;
const int pwm_chb = 11;
const int dir_cha = 12;
const int dir_chb = 13;
const int brake_cha = 9;
const int brake_chb = 8;
const int Pin1=2;
const int Pin2=4;
int spr=100;

Stepper stepper(num_step, dir_cha, dir_chb);
Bounce Bounce1 = Bounce(Pin1,5);
Bounce Bounce2 = Bounce(Pin2,5);
void setup()
{
    Serial.begin(9600);
    pinMode(pwm_cha, OUTPUT);
    pinMode(pwm_chb, OUTPUT);
    pinMode(brake_cha, OUTPUT);
    pinMode(brake_chb, OUTPUT);
    digitalWrite(pwm_cha, HIGH);
    digitalWrite(pwm_chb, HIGH);
    digitalWrite(brake_cha, LOW);
    digitalWrite(brake_chb, LOW);
    pinMode(Pin1,INPUT);
    pinMode(Pin2,INPUT);
    digitalWrite(Pin1,HIGH);
    digitalWrite(Pin2,HIGH);
}

void loop()
{
Bounce1.update ( );
Bounce2.update ( );
int ValB1=Bounce1.read();
int ValB2=Bounce2.read();
if (ValB1 &&!ValB2)
{digitalWrite(pwm_cha, HIGH);digitalWrite(pwm_chb, HIGH);
stepper.step(spr);stepper.setSpeed(400);}
if(!ValB1&&ValB2)
{digitalWrite(pwm_cha, HIGH);digitalWrite(pwm_chb, HIGH);
stepper.step(-spr);stepper.setSpeed(400);}
if ( !ValB1 && !ValB2){digitalWrite(pwm_cha, LOW);digitalWrite(pwm_chb, LOW);}
}

TheBlommie

Hi Ash, I'm starting to think that maybe there is a problem with the library because I get the following errors with the new code:


Stepper_Arcade_Joystick_Control_FINAL.cpp.o: In function `__static_initialization_and_destruction_0':
C:\Users\Ian\Desktop\arduino-1.0.2/Stepper_Arcade_Joystick_Control_FINAL.ino:15: undefined reference to `Bounce::Bounce(unsigned char, unsigned long)'
C:\Users\Ian\Desktop\arduino-1.0.2/Stepper_Arcade_Joystick_Control_FINAL.ino:16: undefined reference to `Bounce::Bounce(unsigned char, unsigned long)'
Stepper_Arcade_Joystick_Control_FINAL.cpp.o: In function `loop':
C:\Users\Ian\Desktop\arduino-1.0.2/Stepper_Arcade_Joystick_Control_FINAL.ino:36: undefined reference to `Bounce::update()'
C:\Users\Ian\Desktop\arduino-1.0.2/Stepper_Arcade_Joystick_Control_FINAL.ino:37: undefined reference to `Bounce::update()'
C:\Users\Ian\Desktop\arduino-1.0.2/Stepper_Arcade_Joystick_Control_FINAL.ino:38: undefined reference to `Bounce::read()'
C:\Users\Ian\Desktop\arduino-1.0.2/Stepper_Arcade_Joystick_Control_FINAL.ino:39: undefined reference to `Bounce::read()'


Please advice.

Thanks

Go Up