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(p16);
00004 DigitalOut led(LED1);
00005 
00006 Serial pc(USBTX,USBRX);
00007 
00008 Ticker tick;
00009 
00010 
00011 float Vav=0.0;
00012 
00013 void average (void) {
00014     led = !led;
00015     Vav = (Vav + pot)/2.0;
00016 }
00017 
00018 
00019 int main() {
00020 
00021     // run the ticker every 100ms
00022     tick.attach(&average,0.1);
00023 
00024     while (1) {
00025         pc.printf("Average is %.3f\n",Vav);
00026         wait (2.0);
00027 
00028     }
00029 }