hi guys. been lurking awhile now, started first build, , ran first problem.
i'm trying control stepper motor using 4 digital inputs (i intend track moving object w/ lasers).
i'm trying if , else if statements control logic. i've played around w/ hundred ways, motor picks run command. below latest upload. i'm down trying 2 states only. button inputs have no impact on stepper. turns on , runs ccw is, , if re-comment in last array, cycles , fourth. tips?
i'm trying control stepper motor using 4 digital inputs (i intend track moving object w/ lasers).
i'm trying if , else if statements control logic. i've played around w/ hundred ways, motor picks run command. below latest upload. i'm down trying 2 states only. button inputs have no impact on stepper. turns on , runs ccw is, , if re-comment in last array, cycles , fourth. tips?
code: [select]
/////////testing motor run input interlocking/////////
// built using elements arduino examples, custom code, , arduino workshop examples
// [project 1] - stepper motor direction control using 4 digital inputs variable interlocking approvals.
// button inputs replaced ldr's
// mcmullen october 2015.
#include <stepper.h>
int button_1 = 2;
int button_2 = 3;
int button_3 = 4;
int button_4 = 5;
const int stepsperrevolution = 512; // change fit number of steps per revolution (changed 200)
// motor
// initialize stepper library on pins 9 through 12: changed wiring 9-12.
stepper mystepper(stepsperrevolution, 9, 10, 11, 12);
void setup() {
// set speed @ 2 rpm: (changed 60)
mystepper.setspeed(20);
// initialize serial port:
serial.begin(9600);
pinmode(button_1, input);
pinmode(button_2, input);
pinmode(button_3, input);
pinmode(button_4, input);
}
void loop() {
if ((button_1==high)&&(button_3==high)&&(button_2==low)&&(button_4==low))
delay(10000);
//input code restart loop without going further. research indicates needing add "global flag" inreset possibly command.
if ((button_1==low)&&(button_2==high)&&(button_3==high)&&(button_4==high));
//input code turn motor ccw , restart loop
// step 1 revolution ccw
serial.println("counterclockwise");
mystepper.step(-stepsperrevolution);
//if ((button_3==low)&&(button_1==high)&&(button_2==high)&&(button_4==high));
//input code turn motor cw , restart loop
// step 1 revolution cw
// serial.println("clockwise");
// mystepper.step(stepsperrevolution);
}
code: [select]
if ((button_1==high)&&(button_3==high)&
button_1 defined in code 2. high defined in core 1. 2 shall never ever equal. 1 never equal 2.
perhaps instead of comparing pin number state, meant read pin , compare state state.
code: [select]
if(digitalread(button_1) == high && digitalread(button_3) == high && ...
i suggest working through of basic examples until understand of basics of how stuff works before getting more complex.
Arduino Forum > Using Arduino > Programming Questions > Newbie question:
arduino
Comments
Post a Comment