Code Club Electronics 18
I was intending to use a potentiometer to control the motor speed, however using an arduino seems rather overkill for this. So I will just do that directly.
I decided to build a car instead, so far this has 2 wheels and just goes forward.
#include <AFMotor.h>
AF_DCMotor motorA(3);
AF_DCMotor motorB(4);
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-potentiometer
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
//Serial.begin(9600);
motorA.setSpeed(100);
motorA.run(RELEASE);
motorB.setSpeed(100);
motorB.run(RELEASE);
}
// the loop routine runs over and over again forever:
void loop() {
//Motor spinning clockwise
motorA.run(FORWARD);
//Speed up
motorA.setSpeed(100);
motorB.run(FORWARD);
//Speed up
motorB.setSpeed(100);
}
#Arduino,#Robot,#Car,#InitialCode
Mastodon | Peertube | Join Mastodon |