Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:127d52afa7a9
- Child:
- 1:497b52a2d414
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jun 22 12:59:06 2017 +0000
@@ -0,0 +1,55 @@
+/* 3pi Example 2
+
+(c) Dr Craig A. Evans, University of Leeds
+
+June 2017
+
+*/
+
+#include "mbed.h"
+#include "m3pi.h"
+
+// API objects
+m3pi buggy;
+AnalogIn pot_P(p15);
+
+// Function Prototypes
+void init();
+
+// Main Function
+int main()
+{
+ init();
+
+ // move cursor to position (0,0) - top-left
+ buggy.lcd_goto_xy(0,0);
+ // print on the LCD - the number 5 is the number of characters in the string
+ buggy.lcd_print("Ex. 2",5);
+
+ // we will update the motors 50 times per second
+ float dt = 1.0/50.0;
+
+ // main loop - this runs forever
+ while(1) {
+
+ // this returns a value in the range 0.0 to 1.0
+ float pot_P_val = pot_P.read();
+
+ // change to -1.0 to 1.0
+ float motor_speed = 2.0*pot_P_val-1.0;
+ // this gives full-speed backward (-1.0) to full-speed forward
+
+ // set the speed of the left and right motors
+ buggy.motors(motor_speed,motor_speed);
+
+ // wait for a short time before repeating the loop
+ wait(dt);
+
+ }
+}
+
+// Functions
+void init()
+{
+ buggy.init();
+}
\ No newline at end of file