“MCookie-Motor/zh”的版本间的差异
853387039@qq.com(讨论 | 贡献) (→应用) |
853387039@qq.com(讨论 | 贡献) |
||
第5行: | 第5行: | ||
[[File:motor-motor-rect.jpg|400px|thumb|right|mCookie-Motor]] | [[File:motor-motor-rect.jpg|400px|thumb|right|mCookie-Motor]] | ||
− | mCookie- | + | mCookie-Motor是一款直流电机(马达)控制器,具有脉宽调制,可通过PWM控制电机速度。必须使用BM模块供电。 |
第18行: | 第18行: | ||
==规格== | ==规格== | ||
− | * | + | *外部供电:BM模块供电。 |
*引脚说明 | *引脚说明 | ||
{|class="wikitable" | {|class="wikitable" | ||
− | ! rowspan="1" |Motor芯片引脚| | + | ! rowspan="1" mCookie引脚||Motor芯片引脚|||功能 |
|- | |- | ||
− | | | + | | D6|| 1A||控制1A高电平,顺时针转 |
|- | |- | ||
− | | | + | | D8|| 1B||控制1B高电平,逆时针转 |
|- | |- | ||
− | | | + | | D5|| 2A||控制2A高电平,顺时针转 |
|- | |- | ||
− | | | + | | D7|| 2B||控制2A高电平,顺时针转 |
|- | |- | ||
| VMOT||BM模块||供电 | | VMOT||BM模块||供电 | ||
第35行: | 第35行: | ||
| GND||GND||共地 | | GND||GND||共地 | ||
|} | |} | ||
+ | '''注意:使用Motor模块驱动电机5,6,7,8这几个引脚不能被其他传感器占用,否则会出现问题''' | ||
[[File:motor-Pinout-1Big.jpg|800px|thumb|center]] | [[File:motor-Pinout-1Big.jpg|800px|thumb|center]] | ||
第45行: | 第46行: | ||
===直流电机接线=== | ===直流电机接线=== | ||
+ | *将一个直流电机接(OUT1A,OUT1B),另外一个直流电机接(OUT2A,OUT2B); | ||
+ | *直流电机控制引脚: | ||
+ | <source lang="cpp"> | ||
+ | //D6,D8控制1A,1B的电机 | ||
+ | #define OUT1A 6 | ||
+ | #define OUT1B 8 | ||
+ | //D5,D7控制2A,2B的电机 | ||
+ | #define OUT2A 5 | ||
+ | #define OUT2B 7 | ||
+ | </source> | ||
− | + | ===直流电动机控制方式=== | |
− | |||
− | |||
{|class="wikitable" | {|class="wikitable" | ||
− | ! rowspan="1" | | + | ! rowspan="1" |6||8||5||7||1A||1B||2A||2B||功能 |
|- | |- | ||
− | | | + | |Low||Low||Low||Low||Off||Off||Off||Off||关闭(惯性停下) |
|- | |- | ||
− | | | + | |High||Low||High||Low||High||Low||High||Low||顺时针转 |
|- | |- | ||
− | | | + | |Low||High||Low||High||Low||High||Low||High||逆时针转 |
|- | |- | ||
− | | | + | |High||High||High||High||Low||Low||Low||Low||急停 |
|} | |} | ||
+ | ==PWM速度控制方式=== | ||
==应用== | ==应用== | ||
*通断控制 | *通断控制 | ||
+ | <source lang="cpp"> | ||
+ | #define OUT1A 6 | ||
+ | #define OUT1B 8 | ||
+ | #define OUT2A 5 | ||
+ | #define OUT2B 7 | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | pinMode(OUT1A, OUTPUT); | ||
+ | pinMode(OUT1B, OUTPUT); | ||
+ | pinMode(OUT2A, OUTPUT); | ||
+ | pinMode(OUT2B, OUTPUT); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | head(); | ||
+ | delay(2000); | ||
+ | back(); | ||
+ | delay(1000); | ||
+ | stop(); | ||
+ | delay(500); | ||
+ | } | ||
+ | |||
+ | void head() | ||
+ | { | ||
+ | digitalWrite(OUT1A, HIGH); | ||
+ | digitalWrite(OUT1B, LOW); | ||
+ | digitalWrite(OUT2A, HIGH); | ||
+ | digitalWrite(OUT2B, LOW); | ||
+ | } | ||
+ | void back() | ||
+ | { | ||
+ | digitalWrite(OUT1A, LOW); | ||
+ | digitalWrite(OUT1B, HIGH); | ||
+ | digitalWrite(OUT2A, LOW); | ||
+ | digitalWrite(OUT2B, HIGH); | ||
+ | } | ||
+ | void stop() | ||
+ | { | ||
+ | digitalWrite(OUT1A, LOW); | ||
+ | digitalWrite(OUT1B, LOW); | ||
+ | digitalWrite(OUT2A, LOW); | ||
+ | digitalWrite(OUT2B, LOW); | ||
+ | } | ||
+ | </source> | ||
*PWM调速控制 | *PWM调速控制 | ||
+ | <source lang="cpp"> | ||
+ | //D6,D8控制1A,1B的电机 | ||
+ | #define OUT1A 6 | ||
+ | #define OUT1B 8 | ||
+ | //D5,D7控制2A,2B的电机 | ||
+ | #define OUT2A 5 | ||
+ | #define OUT2B 7 | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | pinMode(OUT1A, OUTPUT); | ||
+ | pinMode(OUT1B, OUTPUT); | ||
+ | pinMode(OUT2A, OUTPUT); | ||
+ | pinMode(OUT2B, OUTPUT); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5) | ||
+ | //循环语句,控制PWM速度增加,控制fadeValue的变化大小可以控制亮度级别 | ||
+ | { | ||
+ | analogWrite(OUT1A, fadeValue); //将速度级别写入电机 | ||
+ | digitalWrite(OUT1B, LOW); | ||
+ | analogWrite(OUT2A, fadeValue); | ||
+ | digitalWrite(OUT2B, LOW); | ||
+ | delay(100); //速度度级别维持的时间,单位毫秒 | ||
+ | } | ||
+ | delay(1000); | ||
+ | for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) | ||
+ | //循环语句,控制PWM速度减小,控制fadeValue的变化大小可以控制亮度级别 | ||
+ | { | ||
+ | digitalWrite(OUT1A, LOW); | ||
+ | analogWrite(OUT1B, fadeValue); //将速度级别写入电机 | ||
+ | digitalWrite(OUT2A, LOW); | ||
+ | analogWrite(OUT2B, fadeValue); | ||
+ | delay(100); //速度度级别级别维持的时间,单位毫秒 | ||
+ | } | ||
+ | delay(1000); | ||
+ | } | ||
+ | </source> | ||
'''其它应用:''' | '''其它应用:''' | ||
2015年8月25日 (二) 08:40的版本
Language | English |
---|
mCookie-Motor是一款直流电机(马达)控制器,具有脉宽调制,可通过PWM控制电机速度。必须使用BM模块供电。
特色
规格
注意:使用Motor模块驱动电机5,6,7,8这几个引脚不能被其他传感器占用,否则会出现问题 文档开发直流电机接线
//D6,D8控制1A,1B的电机
#define OUT1A 6
#define OUT1B 8
//D5,D7控制2A,2B的电机
#define OUT2A 5
#define OUT2B 7
直流电动机控制方式
PWM速度控制方式=应用
#define OUT1A 6
#define OUT1B 8
#define OUT2A 5
#define OUT2B 7
void setup()
{
pinMode(OUT1A, OUTPUT);
pinMode(OUT1B, OUTPUT);
pinMode(OUT2A, OUTPUT);
pinMode(OUT2B, OUTPUT);
}
void loop()
{
head();
delay(2000);
back();
delay(1000);
stop();
delay(500);
}
void head()
{
digitalWrite(OUT1A, HIGH);
digitalWrite(OUT1B, LOW);
digitalWrite(OUT2A, HIGH);
digitalWrite(OUT2B, LOW);
}
void back()
{
digitalWrite(OUT1A, LOW);
digitalWrite(OUT1B, HIGH);
digitalWrite(OUT2A, LOW);
digitalWrite(OUT2B, HIGH);
}
void stop()
{
digitalWrite(OUT1A, LOW);
digitalWrite(OUT1B, LOW);
digitalWrite(OUT2A, LOW);
digitalWrite(OUT2B, LOW);
}
//D6,D8控制1A,1B的电机
#define OUT1A 6
#define OUT1B 8
//D5,D7控制2A,2B的电机
#define OUT2A 5
#define OUT2B 7
void setup()
{
pinMode(OUT1A, OUTPUT);
pinMode(OUT1B, OUTPUT);
pinMode(OUT2A, OUTPUT);
pinMode(OUT2B, OUTPUT);
}
void loop()
{
for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5)
//循环语句,控制PWM速度增加,控制fadeValue的变化大小可以控制亮度级别
{
analogWrite(OUT1A, fadeValue); //将速度级别写入电机
digitalWrite(OUT1B, LOW);
analogWrite(OUT2A, fadeValue);
digitalWrite(OUT2B, LOW);
delay(100); //速度度级别维持的时间,单位毫秒
}
delay(1000);
for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5)
//循环语句,控制PWM速度减小,控制fadeValue的变化大小可以控制亮度级别
{
digitalWrite(OUT1A, LOW);
analogWrite(OUT1B, fadeValue); //将速度级别写入电机
digitalWrite(OUT2A, LOW);
analogWrite(OUT2B, fadeValue);
delay(100); //速度度级别级别维持的时间,单位毫秒
}
delay(1000);
}
其它应用: 购买历史图库视频 |