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, 8 months ago.
Source Code of AnalogIn
Hi, Does anyone where the source code of this analogIn is? I want to learn about how mbed programs the ADC.
Question relating to:
1 Answer
9 years, 8 months ago.
I'd suggest importing a program such as this: http://developer.mbed.org/users/thudt90/code/mbed_blinky/
From there use the text navigation in the online IDE to jump around and see what calls are being made. Make sure to update mbed-src as your platform may not have been present when this program was published.
Hi Sam,
The blinky code does not use any analogIn there. Is this what you intended me to look over?
posted by 10 Apr 2015Just add your own Analog in code or start from an example snippet and start clicking around. Here is the documentation: http://developer.mbed.org/handbook/AnalogIn
#include "mbed.h" // Initialize a pins to perform analog input and digital output fucntions AnalogIn ain(A0); DigitalOut dout(LED1); int main(void) { while (1) { // test the voltage on the initialized analog pin // and if greater than 0.3 * VCC set the digital pin // to a logic 1 otherwise a logic 0 if(ain > 0.3f) { dout = 1; } else { dout = 0; } // print the percentage and 16 bit normalized values printf("percentage: %3.3f%%\n", ain.read()*100.0f); printf("normalized: 0x%04X \n", ain.read_u16()); wait(0.2f); } }