AnalogOut on LPC1768


Recently I started using LPC1768 and I have a problem with AnalogOut. I tried to identify the issue but I couldn’t so decided to post here.

I’m sending an audio signal to PIN15 and probing at PIN18 but there is no audio signal.

Here is my code:

#include “mbed.h”

//mbed objects
AnalogIn Ain(p15);
AnalogOut Aout(p18);

//variables and data
float data;

//main program start here
int main() {
data = Ain - 0.5;
Aout = data + 0.5;

I also tried just “Aout = Ain” but there was no AnalogOut signal neither.
I see the input signal swinging at PIN15 after the bias circuit (below) so I believe something I’m doing wrong in coding.

Thanks for your advice in advance.


Well, for a start (if your code is actually as you quoted) you’re only sampling the analog input once.

MbedOS isn’t like Arduino where the ‘main’ loop automatically repeats continuously.

You have to put the analog input instruction into a loop to continually sample the analog voltage - after that you can process it how you want.

Some serial port print statements can be useful to show you what the code is doing…

Oh thank you so much, it makes sense.

I rapped around my main codes in while loop and it works now!