hi I wrote this code for this exercise
Reads input through the ADC, and transfers to PC terminal
- 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
hi I wrote this code for this exercise
Reads input through the ADC, and transfers to PC terminal
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