第四步,Arduino程序和调试
关于程序,我们列出初始化部分和主程序,以便让大家对其有个了解。这里要强调一点的是我们使用了ladyada.net设计的电机驱动库AFMotor,大家需要把解压后的文件放到Arduino安装目录libraries的文件夹下。
程序片段如下:
ARDUINO代码
/*
BOXZ is is an open source robot platform for interactive entertainment!
We connected Arduino,Plexiglass(PMMA) Origami and your idea together,
so we can easily and quickly build a remote robot by ourself!
We can use it to playing football game, racing, fighting or some other interesting things!
Author: Guangjun Zhu
Email: [email]zgj0729@163.com[/email]
Code license: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
*/
#include
#include
/*
b_motor_stop(): stop motor
b_motor_com(): for Manual Operator
b_servo_ini();
b_servo_com();
b_skill();
*/
//-------------------define motor----------------------------------------------//
AF_DCMotor motorL(1,MOTOR12_8KHZ); //connect to M1
AF_DCMotor motorR(2,MOTOR12_8KHZ); //connect to M2
int motor_speed = 200; //[modifid]motor speed 150-200,---min:100;max:255
int motor_delay = 400; //[modifid]delay time in step
//-------------------define servo----------------------------------------------//
Servo hand_l_servo; // create servo object to control a servo
Servo hand_r_servo; // create servo object to control a servo
int hand_l_pos = 90; //
int hand_r_pos = 90; //
int hand_delay = 1; //[modifid] speed of hand
//------------------main program-----------------------------------------------//
void setup()
{
Serial.begin(9600);
b_motor_stop();
b_servo_ini();
delay(2000); //waiting time
Serial.println("Hello! BOXZ!");
}
void loop()
{
int key;
if(Serial.available() > 0) {
key = Serial.read();
if(key >= 30 && key