Incubator turning eggs
hi first arduino project.
my project move dc motor running shuttle along bed turn eggs (parts old flat bed scanner) , l293 runs motor
egg holder, box, rocker made.
the following code "should" upon button press or timer move shuttle 1 end other , stop. wait button or timer move other end. each end has push button read shuttle @ end of travel.
if on code not working
my project move dc motor running shuttle along bed turn eggs (parts old flat bed scanner) , l293 runs motor
egg holder, box, rocker made.
the following code "should" upon button press or timer move shuttle 1 end other , stop. wait button or timer move other end. each end has push button read shuttle @ end of travel.
if on code not working
code: [select]
// egg rotation v5
// control small dc motor driven carriage shuttle left right, limit switch @ each end stop travel.
// if switch or timer (not setup yet) triggered, run other end , stop.
int left = 5; //motor on pin 6
int right = 6; // motor on pin 4
int enable = 3; // "h bridge" pwm speed pin 1 on ic
int limitswitchleft = 7; //travel @ full left position on pin 7
int limitswitchright = 8; //travel @ full right position on pin 8
int whereisshuttlenow = 1; //name var current position
int wherewasshuttlelast = 1;// name var ws last
int motorspeed = 200; //set pwm motor speed
int sendcarrage = 2; // switch on pin 2
void setup()
{
pinmode(left, output); //name pin number x output
pinmode(right, output); //name pin number x output
pinmode(enable, output); //name pin number x output
pinmode (limitswitchleft, input); //set switches input
pinmode (limitswitchright, input); // set switches input
pinmode (sendcarrage, input); // set input
//digitalwrite(enable, high); //stop motor travel
wherewasshuttlelast = 1; //set random start position
}
void loop()
{
if (digitalread (sendcarrage) == high) { //see if carrage button pressed or timer code trigger
if (wherewasshuttlelast == -1) {//if shuttle flag last left (-1)
delay (2); //wait clear swtich
runright();
if (digitalread (limitswitchright) == high) { //if carrage full travel right
wherewasshuttlelast = 1;
motorstop();
}
else {
if (wherewasshuttlelast == 1) {//if shuttle flag last right (1)
//if (whereisshuttlenow == 1)
delay (2); //wait clear swtich
runleft();
//move outside sendcarrage command
if (digitalread (limitswitchleft) == high) { //if carriage full travel left
wherewasshuttlelast = -1;
motorstop();
}}}}}
}
////////////////////// end main loop
//setup subs
void runleft(){ // run motor left
digitalwrite(enable, high); // turn on ic chip
analogwrite (right, motorspeed);
digitalwrite (left, low);
}
void runright (){ //run motor right
digitalwrite(enable, high); // turn on ic chip
digitalwrite (right, low);
analogwrite (left, motorspeed);
}
void motorstop(){ //stop motor
digitalwrite(enable, low); // turn on ic chip
digitalwrite (right, low);
digitalwrite (left, low);
}
quote
if on code not workingyou have switches wired in mysterious way. have code something. have failed include relevant details. , want guess why code doesn't want? i'll pass.
Arduino Forum > Using Arduino > Programming Questions > Incubator turning eggs
arduino
Comments
Post a Comment