- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
http://arduinolearning.com/robots/4-wheel-robot-car-basic-example.php
#include <AFMotor.h> AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm AF_DCMotor motor3(3, MOTOR34_1KHZ); // create motor #3, 1KHz pwm AF_DCMotor motor4(4, MOTOR34_1KHZ); // create motor #4, 1KHz pwm void setup() { Serial.begin(9600);//set up Serial library at 9600 bps Serial.println("Motor test!"); MotorSpeed(200); AllForward(); delay(1000); AllBackward(); delay(1000); AllStop(); delay(1000); } void loop() { } void MotorSpeed(int Speed) { motor1.setSpeed(Speed); // set the speed to 200 (255 max) motor2.setSpeed(Speed); motor3.setSpeed(Speed); motor4.setSpeed(Speed); } void AllForward() { Serial.print("forward"); motor1.run(FORWARD); // turn it on going forward motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD); } void AllBackward() { Serial.print("backward"); motor1.run(BACKWARD); // turn it on going forward motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD); } void AllStop() { Serial.print("stop"); motor1.run(RELEASE); // turn it on going forward motor2.run(RELEASE); motor3.run(RELEASE); motor4.run(RELEASE); }
- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
留言
張貼留言