how or where is a example sketch to work off, like to enter f 10 50, to run motor forward at speed 10 for 50 seconds
working off this example and got motors working but need serial input to work properly
// connect motor controller pins to Arduino digital pins
// motor one
int enA = 10;
int in1 = 9;
int in2 = 8;
int inByte = 0 ;
void setup()
{
Serial.begin(9600);
// set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void demoOne()
{
// this function will run the motors in both directions at a fixed speed
// turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// set speed to 200 out of possible range 0~255
analogWrite(enA, inByte);
delay(2000);
// now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(2000);
// now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
void loop()
{
if (Serial.available() > 0) {
int inByte = char (Serial.read()) * 100;
demoOne();
delay(1000);
}}
no luck with this either
// connect motor controller pins to Arduino digital pins
// motor one
int enA = 10;
int in1 = 9;
int in2 = 8;
int serIn; //var that will hold the bytes in read from the serialBuffer
void setup()
{
Serial.begin(9600);
// set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void forward()
{
// this function will run the motors in both directions at a fixed speed
// turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// set speed to 200 out of possible range 0~255
analogWrite(enA, 150);
delay(2000);
// now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enA, 150);
}
void backward()
{
// now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(2000);
// now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
void loop()
{
while (Serial.available()>0){
serIn = Serial.read(); //read Serial
if (serIn == 'a' ) {
void forward () ;
}
if (serIn == 'b' ) {
void backward () ;
}
delay(1000);
}}