Jan Kamidra
/
DAC_MCP4801_example
Simple example
main.cpp@0:da546cd98789, 2020-03-03 (annotated)
- Committer:
- JohnnyK
- Date:
- Tue Mar 03 20:10:21 2020 +0000
- Revision:
- 0:da546cd98789
First release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JohnnyK | 0:da546cd98789 | 1 | #include "mbed.h" |
JohnnyK | 0:da546cd98789 | 2 | #include "MCP4801.h" |
JohnnyK | 0:da546cd98789 | 3 | |
JohnnyK | 0:da546cd98789 | 4 | SPI spi(PA_7,PA_6,PA_5);//tested on Nucleo L432KC |
JohnnyK | 0:da546cd98789 | 5 | MCP4801 dac(spi,PA_4); |
JohnnyK | 0:da546cd98789 | 6 | DigitalOut led(LED2); |
JohnnyK | 0:da546cd98789 | 7 | |
JohnnyK | 0:da546cd98789 | 8 | int main(void) { |
JohnnyK | 0:da546cd98789 | 9 | printf("DAC MCP4801 example starting...\n"); |
JohnnyK | 0:da546cd98789 | 10 | |
JohnnyK | 0:da546cd98789 | 11 | |
JohnnyK | 0:da546cd98789 | 12 | float voltage = 2.8; |
JohnnyK | 0:da546cd98789 | 13 | dac.setVOutput(voltage); |
JohnnyK | 0:da546cd98789 | 14 | printf("Your request was %4.2fV\n", voltage); |
JohnnyK | 0:da546cd98789 | 15 | |
JohnnyK | 0:da546cd98789 | 16 | while(1){ |
JohnnyK | 0:da546cd98789 | 17 | led = !led; |
JohnnyK | 0:da546cd98789 | 18 | ThisThread::sleep_for(500); |
JohnnyK | 0:da546cd98789 | 19 | } |
JohnnyK | 0:da546cd98789 | 20 | } |