标题:
自己写的一个人蓝牙Arduino小车程序源码
[打印本页]
作者:
songyuan
时间:
2018-7-15 16:32
标题:
自己写的一个人蓝牙Arduino小车程序源码
自己写的一个人蓝牙Arduino小车,附件有蓝牙串口助手
0.png
(3.96 KB, 下载次数: 68)
下载附件
2018-7-15 19:04 上传
Arduino源程序如下:
//因为数字端口2和13未被占用,所以我们就要2和13端口来接超声波模块。
#include <AFMotor.h>
//int inputPin=13; // 定义超声波Trig
//int outputPin=2; // 定义超声波Echo
AF_DCMotor motor1(1, MOTOR12_64KHZ);// 创建电机#1号,速度是64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ);// 创建电机#2号,速度是64KHz pwm
AF_DCMotor motor3(3, MOTOR12_64KHZ);// 创建电机#2号,速度是64KHz pwm
AF_DCMotor motor4(4, MOTOR12_64KHZ);// 创建电机#2号,速度是64KHz pwm
void setup()
{
Serial.begin(9600);
//pinMode(inputPin, INPUT);
// pinMode(outputPin, OUTPUT);
motor1.setSpeed(150);// 设置电机速度,从200/255之间任意(我这俩电机速度不一样,所以我就这样设置)
motor2.setSpeed(150);// 设置电机速度,从200/255之间任意(大家可以按照自己的电机转速来调节一样的速度就可以了)
motor3.setSpeed(150);
motor4.setSpeed(150);
Serial.println("Motor test!");
}
void loop()
{
//digitalWrite(outputPin, LOW); // 使发出发出超声波信号接口低电平2μs
//delayMicroseconds(2);
// digitalWrite(outputPin, HIGH); // 使发出发出超声波信号接口高电平10μs,这里是至少10μs
// delayMicroseconds(10);
// digitalWrite(outputPin, LOW); // 保持发出超声波信号接口低电平
// int distance = pulseIn(inputPin, HIGH); // 读出脉冲时间
//distance= distance/58; // 将脉冲时间转化为距离(单位:厘米)
//Serial.println(distance); //输出距离值
delay(3000);
//if (distance < 120 ) //大于50厘米就前进
//小车前进
{
//Serial.print("tick");
motor1.run(FORWARD);// 电机前进
motor2.run(FORWARD);// 电机前进
motor3.run(FORWARD);// 电机前进
motor4.run(FORWARD);// 电机前进
}
delay(3000);
//if (distance > 50) //小雨50厘米就后退
//小车后退
{
//Serial.print("tock");
motor1.run(BACKWARD);// 电机后退
motor2.run(BACKWARD);// 电机后退
motor3.run(BACKWARD);// 电机后退
motor4.run(BACKWARD);// 电机后退
}
//if (distance == 50) //等于50厘米就停止
//小车停止
delay(3000);
{
//Serial.print("tack");
motor1.run(RELEASE);// 电机停止
motor2.run(RELEASE);// 电机停止
motor3.run(RELEASE);// 电机停止
motor4.run(RELEASE);// 电机停止
}
//小车左转
delay(3000);
{
motor1.run(FORWARD);// 电机前进
motor2.run(FORWARD);// 电机前进
motor3.run(BACKWARD);// 电机后退
motor4.run(BACKWARD);// 电机后退
}
//小车右转
delay(3000);
{
motor3.run(FORWARD);// 电机前进
motor4.run(FORWARD);// 电机前进
motor1.run(BACKWARD);// 电机后退
motor2.run(BACKWARD);// 电机后退
}
}
复制代码
所有资料51hei提供下载:
lanyachuankou_41.zip
(1.69 MB, 下载次数: 18)
2018-7-15 16:31 上传
点击文件名下载附件
下载积分: 黑币 -5
1.zip
(1.38 KB, 下载次数: 16)
2018-7-15 16:27 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
迷一样谦谦公子
时间:
2019-4-2 21:03
请问可以出一个app的开发教程么?或者请指教一下
作者:
大猫8888
时间:
2019-6-28 16:12
arduino --board arduino:avr:yun --save-prefs
arduino -v --board arduino:avr:yun --pref build.path=mixlyBuild --verify "F:\Mixly0998/testArduino/testArduino.ino"
F:\Mixly0998\.\arduino-1.8.5\arduino-builder -dump-prefs -logger=machine -hardware F:\Mixly0998\.\arduino-1.8.5\hardware -tools F:\Mixly0998\.\arduino-1.8.5\tools-builder -tools F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -built-in-libraries F:\Mixly0998\.\arduino-1.8.5\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:yun -ide-version=10806 -build-path F:\Mixly0998\mixlyBuild -warnings=null -prefs=build.path=mixlyBuild -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -verbose F:\Mixly0998\testArduino\testArduino.ino
F:\Mixly0998\.\arduino-1.8.5\arduino-builder -compile -logger=machine -hardware F:\Mixly0998\.\arduino-1.8.5\hardware -tools F:\Mixly0998\.\arduino-1.8.5\tools-builder -tools F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -built-in-libraries F:\Mixly0998\.\arduino-1.8.5\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:yun -ide-version=10806 -build-path F:\Mixly0998\mixlyBuild -warnings=null -prefs=build.path=mixlyBuild -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr -verbose F:\Mixly0998\testArduino\testArduino.ino
Using board 'yun' from platform in folder: F:\Mixly0998\arduino-1.8.5\hardware\arduino\avr
Using core 'arduino' from platform in folder: F:\Mixly0998\arduino-1.8.5\hardware\arduino\avr
构建选项已变更,全部重新构建
Detecting libraries used...
"F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_YUN -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8041 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Yun"' "-IF:\Mixly0998\arduino-1.8.5\hardware\arduino\avr\cores\arduino" "-IF:\Mixly0998\arduino-1.8.5\hardware\arduino\avr\variants\yun" "F:\Mixly0998\mixlyBuild\sketch\testArduino.ino.cpp" -o "nul"
"F:\Mixly0998\.\arduino-1.8.5\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10806 -DARDUINO_AVR_YUN -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8041 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Yun"' "-IF:\Mixly0998\arduino-1.8.5\hardware\arduino\avr\cores\arduino" "-IF:\Mixly0998\arduino-1.8.5\hardware\arduino\avr\variants\yun" "F:\Mixly0998\mixlyBuild\sketch\testArduino.ino.cpp" -o "F:\Mixly0998\mixlyBuild\preproc\ctags_target_for_gcc_minus_e.cpp"
F:\Mixly0998\testArduino\testArduino.ino:2:21: fatal error: AFMotor.h: No such file or directory
#include <AFMotor.h>
^
compilation terminated.
exit status 1
编译失败!
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1