ADC workshop example code (DAC) IEEE TAMU
Dependencies: mbed
Fork of mbed_DAC by
main.cpp@0:0c6c66dabc1c, 2015-04-03 (annotated)
- Committer:
- matthewrdestefano
- Date:
- Fri Apr 03 21:09:53 2015 +0000
- Revision:
- 0:0c6c66dabc1c
DAC example code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matthewrdestefano | 0:0c6c66dabc1c | 1 | #include "mbed.h" |
matthewrdestefano | 0:0c6c66dabc1c | 2 | AnalogIn voltage(PTB0); // set the analog input to pin PTB0 |
matthewrdestefano | 0:0c6c66dabc1c | 3 | AnalogOut DACout(PTE30); // set Analog output pin to PTE30 |
matthewrdestefano | 0:0c6c66dabc1c | 4 | int main(void) { |
matthewrdestefano | 0:0c6c66dabc1c | 5 | |
matthewrdestefano | 0:0c6c66dabc1c | 6 | PwmOut led(LED_RED); // set green LED as PWM output |
matthewrdestefano | 0:0c6c66dabc1c | 7 | while (true) // infinite loop |
matthewrdestefano | 0:0c6c66dabc1c | 8 | { |
matthewrdestefano | 0:0c6c66dabc1c | 9 | DACout = DACout + 0.01; // increase the analog output |
matthewrdestefano | 0:0c6c66dabc1c | 10 | if(DACout >= 1.0) // if we reach 100% output |
matthewrdestefano | 0:0c6c66dabc1c | 11 | { |
matthewrdestefano | 0:0c6c66dabc1c | 12 | DACout = 0; // go back to the begining |
matthewrdestefano | 0:0c6c66dabc1c | 13 | } |
matthewrdestefano | 0:0c6c66dabc1c | 14 | led = 1.0 - voltage.read(); // update the LED brightness with ADC data |
matthewrdestefano | 0:0c6c66dabc1c | 15 | wait(0.02); // wait 1/50th of a second |
matthewrdestefano | 0:0c6c66dabc1c | 16 | } |
matthewrdestefano | 0:0c6c66dabc1c | 17 | } |
matthewrdestefano | 0:0c6c66dabc1c | 18 | |
matthewrdestefano | 0:0c6c66dabc1c | 19 | |
matthewrdestefano | 0:0c6c66dabc1c | 20 |