Page 137 - ArduinoและPOP-BOT
P. 137
137
/*******************************************************************************
* POP-BOT V1.0
* Filename : BallSeekerRobot.pde
* Seek ball and move to it.
********************************************************************************/
// *** in this example SLCD connected to pin 16 ***
#include <popbot.h> // Include Library for POP-BOT
#include <gp2d120_lib.h>
#define POW 60
int posValue[] = {170,150,130,110,90,70,50,30,10}; // Servo position value
int j,Minimum,MinPoint;
int GP2[9];
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);
}
int getPoint()
{
int i;
int old=GP2[0]; // Set start element
int min_;
for(i=0;i<9;i++)
{
if(GP2[i]<old)
{
old = GP2[i];
min_ = i;
}
}
Minimum = old;
return(min_);
}
void setup()
{
beep();
sleep(2000);
}
โปรแกรมที่ A11-1 ไฟล BallSeekerRobot.pde โปรแกรมภาษา C ของ Arduino สํ าหรั บตามหาลู กบอลของ
หุ นยนต POP-BOT (มี ต อ)