“MCookie-LEGOShield/zh”的版本间的差异
(→文档) |
|||
第45行: | 第45行: | ||
==文档== | ==文档== | ||
− | + | mcps17 | |
+ | A3906 | ||
+ | Atmega328p | ||
==开发== | ==开发== |
2016年4月22日 (五) 15:02的版本
Language | English |
---|
特色
规格
文档mcps17 A3906 Atmega328p 开发直流电机接线
//D6,D8控制1A,1B的电机
#define OUT1A 6
#define OUT1B 8
//D5,D7控制2A,2B的电机
#define OUT2A 5
#define OUT2B 7
通断控制
#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);
}
PWM调速控制//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); //速度度级别维持的时间,单位毫秒
}
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);
}
应用购买暂不开放购买 历史图库视频 |