Page 343 - Making things move_ DIY mechanisms for inventors, hobbyists, and artists
P. 343
320 Making Things Move
// variables for 4 photocells
int photo_up;
int photo_down;
int photo_left;
int photo_right;
// Set canvas size. 1000 steps is roughly .4 inch
#define CANVASWIDTH 32000
#define CANVASHEIGHT 20000
//total distance for bounds checking
//SADbot starts at center (canvaswidth/2 and canvasheight/2)
float totalWidth = CANVASWIDTH /2;
float totalHeight = CANVASHEIGHT /2;
int randomDirection;
int randomDistance;
void setup()
{
Serial.begin(9600); //start serial printout so we can see stuff
// set motor speed (in RPM)
right_motor.setSpeed(200);
left_motor.setSpeed(200);
//use random seed to get better random numbers
//*set to an analog pin that you're not using
randomSeed(analogRead(4));
}// end setup
void loop()
{
//read and print all sensor values from analog pins 0-3
photo_up = analogRead(0);
Serial.print("up");
Serial.println(photo_up);
photo_down = analogRead(1);
Serial.print("down");
Serial.println(photo_down);
photo_left = analogRead(2);
Serial.print("left");
Serial.println(photo_left);