mimosa 发表于 2012-10-3 23:39:23

对于电驱的使用,PWM操作的疑问?!



const int PIN_MOTOR1_L = 0;
const int PIN_MOTOR1_R = 1;
const int PIN_MOTOR1_S = 2;

void setup() {
Serial.begin(9600);
// 电驱
pinMode(PIN_MOTOR1_L, OUTPUT);
pinMode(PIN_MOTOR1_R, OUTPUT);
pinMode(PIN_MOTOR1_S, OUTPUT);
}

void loop () {
      // 正转
      analogWrite(PIN_MOTOR1_R, 50);
      analogWrite(PIN_MOTOR1_L, LOW);
      digitalWrite(PIN_MOTOR1_S, HIGH);
      // 停
      digitalWrite(PIN_MOTOR1_S, LOW);
      // 反转
      analogWrite(PIN_MOTOR1_R, LOW);
      analogWrite(PIN_MOTOR1_L, 50);
      digitalWrite(PIN_MOTOR1_S, HIGH);
      // 停
      digitalWrite(PIN_MOTOR1_S, LOW);
}

mimosa 发表于 2012-10-3 23:40:46

按照说明做正/反转测试,可是都是正转,我哪里写的不对呢?!:L:curse::'(

小猪会轮滑 发表于 2012-10-4 16:00:13

完整代码在哪里?我的也不行:'(:'(:'(:'(:'(:'(

mimosa 发表于 2012-10-4 16:15:26

小猪会轮滑 发表于 2012-10-4 16:00 static/image/common/back.gif
完整代码在哪里?我的也不行

你是在“wingxine”店里买的吗?!


店家提供的测试方法,我试了没问题~

绿林网页 发表于 2012-10-4 16:48:06

0,1,2都不能输出pwm吧,用 3,5,6脚试试看!

Ansifa 发表于 2012-10-4 19:33:55

楼上正解,012不能analogwrite

Ansifa 发表于 2012-10-4 19:34:12

const int PIN_MOTOR1_L = 3;
const int PIN_MOTOR1_R = 5;
const int PIN_MOTOR1_S = 6;

mimosa 发表于 2012-10-4 21:59:51

:D:D:D:D:D:D
多谢各位果真是不能用0和1,换234就好了,谢谢各位~~~

mimosa 发表于 2012-10-4 22:01:17

// 电驱
const byte MOTOR = { { 2, 3, 4 }, { 5, 6, 7 } }; // LPWM, RPWM, EN工作很顺利~~~:P

太行摄狼 发表于 2012-10-6 22:57:02

恭喜楼主:P
页: [1]
查看完整版本: 对于电驱的使用,PWM操作的疑问?!