![](/media/cache/profiles/a36470cf1f8e5aaf38466d65bd080699.jpg.50x50_q85.jpg)
Potentiometers
Diff: main.cpp
- Revision:
- 0:74d086537907
- Child:
- 1:d957f119593e
--- /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); + + } +}