Insert this into Randi's program!

Dependencies:   m3pi_ng mbed

Committer:
satyson
Date:
Wed May 21 12:26:34 2014 +0000
Revision:
0:5318196e952d
This is for turning around

Who changed what in which revision?

UserRevisionLine numberNew contents of line
satyson 0:5318196e952d 1 #include "mbed.h"
satyson 0:5318196e952d 2 #include "m3pi_ng.h"
satyson 0:5318196e952d 3
satyson 0:5318196e952d 4 DigitalOut myled(LED1);
satyson 0:5318196e952d 5 void turn_around (int array[5]);
satyson 0:5318196e952d 6 m3pi George;
satyson 0:5318196e952d 7
satyson 0:5318196e952d 8 int main()
satyson 0:5318196e952d 9 {
satyson 0:5318196e952d 10
satyson 0:5318196e952d 11 }
satyson 0:5318196e952d 12
satyson 0:5318196e952d 13 void turn_around (int array[5])
satyson 0:5318196e952d 14 {
satyson 0:5318196e952d 15 // Declaring Variables
satyson 0:5318196e952d 16 int threshold = 200;
satyson 0:5318196e952d 17 int speed = 0.3;
satyson 0:5318196e952d 18
satyson 0:5318196e952d 19 bool turn = true;
satyson 0:5318196e952d 20 //NOT NEEDED : int amt = 0;
satyson 0:5318196e952d 21 // Check to see if all sensors are lower than threshold
satyson 0:5318196e952d 22
satyson 0:5318196e952d 23 for(int i = 0; i < 5; i++)
satyson 0:5318196e952d 24 {
satyson 0:5318196e952d 25 if(array[i] > threshold)
satyson 0:5318196e952d 26 {
satyson 0:5318196e952d 27 turn = false;
satyson 0:5318196e952d 28 }
satyson 0:5318196e952d 29
satyson 0:5318196e952d 30 }
satyson 0:5318196e952d 31
satyson 0:5318196e952d 32 while (turn)
satyson 0:5318196e952d 33 {
satyson 0:5318196e952d 34 George.left_motor(speed);
satyson 0:5318196e952d 35 George.right_motor(-speed);
satyson 0:5318196e952d 36
satyson 0:5318196e952d 37 for(int i = 0; i < 5; i++)
satyson 0:5318196e952d 38 {
satyson 0:5318196e952d 39 if(array[i] > threshold)
satyson 0:5318196e952d 40 {
satyson 0:5318196e952d 41 turn = true;
satyson 0:5318196e952d 42 }
satyson 0:5318196e952d 43 }
satyson 0:5318196e952d 44
satyson 0:5318196e952d 45 }
satyson 0:5318196e952d 46 }