Page 105 - ArduinoและPOP-BOT
P. 105
105
/*******************************************************************************
* POP-BOT V1.0
* Filename : SimpleTrackline.pde
* simple track black line
********************************************************************************/
// *** in this example SLCD connected to pin 16 ***
#include <popbot.h> // Include library for POP-BOT
#define POW 80
#define Ref 500
int left;
int right;
void forward(unsigned int time)
{
motor(1,POW);
motor(2,POW);
sleep(time);
}
void turn_left(unsigned int time)
{
motor(1,-POW);
motor(2,POW);
sleep(time);
}
void turn_right(unsigned int time)
{
motor(1,POW);
motor(2,-POW);
sleep(time);
}
void setup()
{
}
void loop()
{
left = analog(3);
right = analog(1);
if(left>Ref && right>Ref)
{
forward(1);
}
if(left<Ref && right>Ref)
{
turn_left(10);
}
if(left>Ref && right<Ref)
{
turn_right(10);
}
}
โปรแกรมที่ A5-1 ไฟล SimpleTrackline.pde โปรแกรมภาษา C ของ Arduino สํ าหรั บควบคุ มให หุ นยนต
POP-BOT เคลื่ อนที่ ตามเส นสี ดํ า