MCookie-LEGOShield/zh
Language | English |
---|
目录特色
规格
文档mcps17 A3906 Atmega328p 开发shield采用IIC接口通讯,IIC地址默认为0x08,就像其他芯片一样读写寄存器地址。 API接口说明.pdf
使用乐高NXT接口按键//D6,D8控制1A,1B的电机
#define OUT1A 6
#define OUT1B 8
//D5,D7控制2A,2B的电机
#define OUT2A 5
#define OUT2B 7
使用乐高NXT接口电机常用方法: 设置固定的速度使用乐高NXT接口超声波常用方法: 获取当前的距离#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);
}
应用购买暂不开放购买 历史图库视频 |