Seeedstudio Arch Examples : Analog - Potentiometer example

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 AnalogIn pot(P0_11);   /* Potentiometer middle pin connected to P0_11, other two ends connected to GND and 3.3V */
00004 DigitalOut led(LED1);  /* LED blinks with a delay based on the analog input read */
00005 
00006 int main()
00007 {
00008     float ain;   /* Variable to store the analog input*/
00009 
00010     while(1) {
00011         ain = pot.read(); /* Read analog value (output will be any value between 0 and 1 */
00012         led = 1;          /* Switch ON LED        */
00013         wait(ain);        /* Wait for 'ain' Seconds (maximum delay is 1 seconds)*/
00014         led = 0;          /* Switch Off LED       */
00015         wait(ain);        /* Wait for 'ain' Seconds (maximum delay is 1 seconds)*/
00016     }
00017 }