mbed course analogin exercise 2

06 Mar 2012

hi I wrote this code for this exercise

Reads input through the ADC, and transfers to PC terminal

  1. include "mbed.h"

Serial pc(USBTX, USBRX); AnalogIn Ain(p20); float ADCdata; DigitalOut mled1(LED1); DigitalOut mled2(LED2); DigitalOut mled3(LED3); DigitalOut mled4(LED4);

int main() { pc.printf("ADC Data Values... \n\r"); while (1) { ADCdata=Ain; pc.printf("%f \n\r",ADCdata); wait (0.5); if (Ain<=0.2) {

mled1=0; mled2=0; mled3=0; mled4=0;

}

if (0.2<Ain<=0.4) {

mled1=1; mled2=0; mled3=0; mled4=0;

}

if (0.4<Ain<=0.6) {

mled1=1; mled2=1; mled3=0; mled4=0;

}

if (0.6<Ain<=0.8) {

mled1=1; mled2=1; mled3=1; mled4=0;

}

if (0.8<Ain<=1) {

mled1=1; mled2=1; mled3=1; mled4=1;

}

} }

but when it doesn work :S. because when I change potenciometer value the mbed leds do not change their state (on/off). I would like to know what is my mistake :S

07 Mar 2012

which mbed? how did you connect the potentiometer and which size does it have? ... and please use <<code>> tags for sourcecode!