Ryo Od
/
Nucleo_MCP3008_Ticker_Test
MCP3008 and Ticker Class Test
main.cpp
- Committer:
- ryood
- Date:
- 2017-06-11
- Revision:
- 1:c437fef79bc3
- Parent:
- 0:0e326a52b0f4
- Child:
- 3:589f800b8980
File content as of revision 1:c437fef79bc3:
#include "mbed.h" #include "mcp3008.h" #define SAMPLING_RATE (48000) #define SAMPLING_PERIOD (1.0f/SAMPLING_RATE) DigitalOut checkPin(D2); void isr() { checkPin = 1; wait_us(1); checkPin = 0; } int main() { SPI spiM(SPI_MOSI, SPI_MISO, SPI_SCK); spiM.frequency(4000000); MCP3008 mcp3008_0(spiM, D10); MCP3008 mcp3008_1(spiM, D9); float v0[8]; float v1[8]; Ticker t; t.attach(&isr, SAMPLING_PERIOD); for (;;) { for (int i = 0; i < 8; i++) { v0[i] = mcp3008_0.read_input(i); } for (int i = 0; i < 8; i++) { v1[i] = mcp3008_1.read_input(i); } printf("Device0\t"); for (int i = 0; i < 8; i++) { printf("%.3f\t", v0[i]); } printf("\r\n"); printf("Device1\t"); for (int i = 0; i < 8; i++) { printf("%.3f\t", v1[i]); } printf("\r\n"); wait(0.2); } }