Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 9 months ago.
analog in
We are trying to use analog in coding. According to instantaneous voltage given to analog pin, corresponding loop must be executed. But its not working for a simple else code./media/uploads/pprs/code.docx
- include "mbed.h"
AnalogIn ain(p20); DigitalOut myled(LED1); DigitalOut myled1(LED2); int main(void) { while(1) { float p=ain.read(); if(ain<0.4f) { myled=1; myled1=0; } else { myled=0; myled1=1; } } }
2 Answers
9 years, 9 months ago.
float p=ain.read(); << value from analogin transferred to p. <br/> if(ain<0.4f) << wrong, your comparing the wrong variable. it should be: if(p<0.4f) << p is the variable with the value
cheers, Paul
i know what you are saying is good ... how ever i though that too .. but then i see the original link of analogin
https://developer.mbed.org/handbook/AnalogIn
they are using ain<0.3f too ..
posted by 24 Mar 2015