用pwm控制小车电机,获取E18红外数据-Arduino中文社区 - Powered by Discuz! Archiver

sunnyboy1 发表于 2018-4-7 19:11

用pwm控制小车电机,获取E18红外数据

电机程序:
void setup() {
// put your setup code here, to run once:
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
analogWrite(A0, 200);
analogWrite(A1, 200);
}

注:6789为数字IO口,A0A1为模拟IO口。

红外程序:
int num = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:
num = analogRead(A3);
if (num > 500)
    Serial.println("no people");
else
    Serial.println("people");
delay(100);
}

XUWZE 发表于 2018-4-8 11:22

analogWrite(A0, 200);
analogWrite(A1, 200);
这两段是用来调速的吗

sunnyboy1 发表于 2018-5-13 21:27

XUWZE 发表于 2018-4-8 11:22
analogWrite(A0, 200);
analogWrite(A1, 200);
这两段是用来调速的吗

对,这个是用pwm波进行调速
页: [1]
查看完整版本: 用pwm控制小车电机,获取E18红外数据