“MCookie-LEGOShield/zh”的版本间的差异
(→特色) |
|||
第13行: | 第13行: | ||
==特色== | ==特色== | ||
− | * | + | *4路电机接口,兼容乐高NXT电机; |
− | * | + | *4路普通传感器接口,兼容NXT接口的按键、声音传感器等; |
− | * | + | *2路全功能传感器接口,除了能兼容普通传感器接口的所有传感器之外,兼容NXT接口的超声波传感器和颜色传感器; |
− | * | + | *IIC接口通讯,不占用其他多余IO口 |
==规格== | ==规格== |
2016年4月20日 (三) 08:07的版本
Language | English |
---|
特色
规格
文档开发直流电机接线
//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);
}
应用购买历史图库视频 |