位置情報を知るための電圧値を表示させる
Dependencies: mbed
adc.cpp
- Committer:
- sayan2
- Date:
- 2020-03-10
- Revision:
- 1:c3989f45366c
- Parent:
- 0:aaea4a22c294
- Child:
- 2:d665c2b3e24f
File content as of revision 1:c3989f45366c:
#include "mbed.h" SPI mySPI(D11, D12, A4); // mosi, miso, sclk DigitalOut cs(D10); Serial pc(USBTX, USBRX); // tx, rx float Vref = 5.0 ; int main(){ cs=1; mySPI.format(8,0); //Setup the spi for 10 bit data, spi mode 0 mySPI.frequency(1000000); // second edge capture, with a 1MHz clock rate while (1){ cs=0; int highByte = mySPI.write(0b01101000); //Send the command to recieve the slave data pc.printf("highByte: %d ",highByte); int lowByte = mySPI.write(0xFF); // send dummy byte to receive the slave data pc.printf("lowByte: %d ",lowByte); int wasteByte = mySPI.write(0x00); cs=1; int dataCh0 = ((highByte << 8) + lowByte)&0x03FF; float volts = dataCh0*Vref /1024; pc.printf("CH0 %f V\n",volts); //cs=1; wait(3); } }