Hi, this is my first time on here since I am still really new to Arduino. I am trying to make a simple robot like a Roomba of some sort that will avoid things like walls or ledges and I have that part done and it works well but I cant seem to figure out how to make the motors turn at the same time when there is no obstacle. I am using cheap stepper library.
Here is my code:
#include <CheapStepper.h>
CheapStepper stepper (4,5,6,7);
CheapStepper stepper1 (9,10,11,12);
int pushButton = 3;
void setup() {
// put your setup code here, to run once:
pinMode(0,INPUT);
pinMode(pushButton,INPUT);
Serial.begin(9600);
stepper.setRpm(18);
stepper1.setRpm(18);
}
void loop() {
int buttonState = digitalRead (pushButton);
Serial.println(buttonState);
Serial.println(digitalRead(0));
if (digitalRead(3)==1 || digitalRead(0)==0){
//both motors
stepper1.moveDegreesCCW (200);
stepper.moveDegreesCCW (200);
//single motor
stepper.moveDegreesCCW (400);
}
else{
// both motors
stepper.moveDegreesCW (40);
stepper1.moveDegreesCW (40);
}
}
Robot.ino (787 Bytes)