1 #include <pololu/orangutan.h>
2 
3 /*
4  * motors1: for the Orangutan LV, SV, SVP, X2, Baby-O and 3pi robot.
5  *
6  * This example uses the OrangutanMotors functions to drive
7  * motors in response to the position of user trimmer potentiometer
8  * and blinks the red user LED at a rate determined by the trimmer
9  * potentiometer position.  It uses the OrangutanAnalog library to measure
10  * the trimpot position, and it uses the OrangutanLEDs library to provide
11  * limited feedback with the red user LED.
12  *
13  * http://www.pololu.com/docs/0J20
14  * http://www.pololu.com
15  * http://forum.pololu.com
16  */
17 
main()18 int main()
19 {
20   while(1)
21   {
22     // note that the following line could also be accomplished with:
23     // int pot = analogRead(7);
24     int pot = read_trimpot();    // determine the trimpot position
25     int motorSpeed = pot/2-256;  // turn pot reading into number between -256 and 255
26 	if(motorSpeed == -256)
27 		motorSpeed = -255; // 256 is out of range
28     set_motors(motorSpeed, motorSpeed);
29 
30     int ledDelay = motorSpeed;
31 	if(ledDelay < 0)
32 	  ledDelay = -ledDelay;  // make the delay a non-negative number
33 	ledDelay = 256-ledDelay; // the delay should be short when the speed is high
34 
35     red_led(1);       // turn red LED on
36     delay_ms(ledDelay);
37 
38     red_led(0);       // turn red LED off
39 	delay_ms(ledDelay);
40   }
41 }
42