ADC workshop example code (DAC) IEEE TAMU

Dependencies:   mbed

Fork of mbed_DAC by Matthew DeStefano

main.cpp

Committer:
matthewrdestefano
Date:
2015-04-03
Revision:
0:0c6c66dabc1c

File content as of revision 0:0c6c66dabc1c:

#include "mbed.h"
AnalogIn voltage(PTB0); // set the analog input to pin PTB0
AnalogOut DACout(PTE30); // set Analog output pin to PTE30
int main(void) {
    
    PwmOut led(LED_RED); // set green LED as PWM output
    while (true) // infinite loop
    {
        DACout = DACout + 0.01; // increase the analog output
        if(DACout >= 1.0) // if we reach 100% output
        {
            DACout = 0; // go back to the begining
        }
        led = 1.0 - voltage.read(); // update the LED brightness with ADC data
        wait(0.02); // wait 1/50th of a second
    }
}