Page 335 - Making things move_ DIY mechanisms for inventors, hobbyists, and artists
P. 335
312 Making Things Move
int photo_left;
int photo_right;
void setup()
{
Serial.begin(9600); //start serial printout so we can see stuff
// set motor speeds (in RPM)
right_motor.setSpeed(200);
left_motor.setSpeed(200);
}
void loop()
{
//read and print all photocell 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);
photo_right = analogRead(3);
Serial.print("right");
Serial.println(photo_right);
delay(1000); //give me time to read them in the monitor
//store photocell values in an array
int photoValues[]= {photo_up, photo_down, photo_left, photo_right};
lowest = 9999; //set this higher than possible photocell values
//loop to find lowest photocell value
for(i = 0;i<4; i++) //4 = number of photocells
{
Serial.println(photoValues[i]); //prints out photoValue array