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.
Fork of 1620_App_Board_Pots by
Diff: main.cpp
- Revision:
- 0:74d086537907
- Child:
- 1:30d1c1087477
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Feb 24 14:54:55 2017 +0000
@@ -0,0 +1,31 @@
+/* ELEC1620 Application Board Example
+
+Potentiometers
+
+(c) Dr Craig A. Evans, University of Leeds, Feb 2017
+
+*/
+
+#include "mbed.h"
+
+AnalogIn pot0(p20);
+AnalogIn pot1(p19);
+AnalogIn pot2(p17);
+
+int main() {
+
+ while(1) {
+
+ float pot0_val = pot0.read(); // returns a float in the range 0.0 to 1.0
+ //float pot0_val = pot0; // short-hand
+
+ float pot0_voltage = pot0_val*3.3f; // multiply by 3.3 to get the voltage
+
+ int pot0_int_val = pot0.read_u16(); // can also get int in range 0 to 65,535
+
+ printf("Pot 0 val = %.2f [%i] (%.2f V)\n",pot0_val,pot0_int_val,pot0_voltage);
+
+ wait(0.2);
+
+ }
+}
