徐州三期 校园全能王-凯伦1号
校园全能王-凯伦1号校园多功能机器人
主要功能:校园引路、校园快递和文件分发、校园卫生打扫、除草。
我们的团队:“群商众议”队作品介绍:智能制造一专多能立足现在 面向未来
硬件及连接
主控板:https://www.dfrobot.com.cn/goods-1204.html
按钮:https://www.dfrobot.com.cn/goods-1274.html
超声波传感器:https://www.dfrobot.com.cn/goods-276.html
电机:https://www.dfrobot.com.cn/goods-362.html
轮子:https://www.dfrobot.com.cn/goods-1354.html
制作步骤:
1.电路连接
2.周边包围制作
3.贴纸上色
4.除草机
5.超声波传感器
6.整体展示
代码
boolean __ardublockDigitalRead(int pinNumber)
{
pinMode(pinNumber, INPUT);
return digitalRead(pinNumber);
}
void setRomeoMotor(int motorId, int speed)
{
int speedPin, directionPin;
if (motorId == 1)
{
speedPin = 6;
directionPin = 7;
}
else
{
if (motorId == 2)
{
speedPin = 5;
directionPin = 4;
}
else
{
return;
}
}
if (speed == 0)
{
digitalWrite(speedPin, LOW);
}
if (speed > 0)
{
digitalWrite(directionPin, HIGH);
analogWrite(speedPin, speed);
}
else
{
digitalWrite(directionPin, LOW);
analogWrite(speedPin, -speed);
}
}
void __ardublockDigitalWrite(int pinNumber, boolean status)
{
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, status);
}
int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin)
{
long duration;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
digitalWrite(trigPin, HIGH);
duration = pulseIn(echoPin, LOW);
duration = duration / 59;
if ((duration <=0) || (duration > 45000)) return false;
delay(50);
return duration;
}
void setup()
{
pinMode( 7 , OUTPUT);
pinMode( 6 , OUTPUT);
pinMode( 5 , OUTPUT);
pinMode( 4 , OUTPUT);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
pinMode( 8 , OUTPUT );
pinMode( 12 , INPUT );
digitalWrite( 8 , HIGH );
delay(500);
}
void loop()
{
if (__ardublockDigitalRead(3))
{
setRomeoMotor(1, 200);
setRomeoMotor(2, 200);
delay( 2000 );
setRomeoMotor(1, 100);
setRomeoMotor(2, 200);
delay( 2000 );
setRomeoMotor(1, 200);
setRomeoMotor(2, 200);
delay( 2000 );
setRomeoMotor(1, 0);
setRomeoMotor(2, 0);
}
else
{
setRomeoMotor(1, 0);
setRomeoMotor(2, 0);
}
if (__ardublockDigitalRead(5))
{
setRomeoMotor(1, -200);
setRomeoMotor(2, -200);
delay( 2000 );
setRomeoMotor(1, -100);
setRomeoMotor(2, -200);
delay( 2000 );
setRomeoMotor(1, -200);
setRomeoMotor(2, -200);
delay( 2000 );
setRomeoMotor(1, 0);
setRomeoMotor(2, 0);
}
else
{
setRomeoMotor(1, 0);
setRomeoMotor(2, 0);
}
if (__ardublockDigitalRead(2))
{
__ardublockDigitalWrite(8, HIGH);
delay( 5000 );
setRomeoMotor(1, 0);
setRomeoMotor(2, 0);
}
else
{
setRomeoMotor(1, 0);
setRomeoMotor(2, 0);
}
if (( ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 8 , 12 ) ) < ( 40 ) ))
{
setRomeoMotor(1, 200);
setRomeoMotor(2, 200);
setRomeoMotor(1, map ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 8 , 12 ) , 3 , 40 , 60 , 255 ) );
setRomeoMotor(2, map ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 8 , 12 ) , 3 , 40 , 60 , 255 ) );
}
else
{
setRomeoMotor(1, 0);
setRomeoMotor(2, 0);
}
}
总结:通过学习,我们了解ARDUINO的主板连接和电路连接,后期小车还可以开发更多的连接和应用。
学习借鉴
页:
[1]