Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed TRP105F_Spline
main.cpp
- Committer:
- aktk
- Date:
- 2016-06-01
- Revision:
- 0:b76e3288e79a
- Child:
- 1:b53d82528534
File content as of revision 0:b76e3288e79a:
#include "mbed.h"
#include "TRP105F_Spline.h"
Serial pc(USBTX, USBRX); // tx, rx ( the usb serial communication )
extern AnalogIn g_Sensor_Voltage;
SPI spi; // mosi(out), miso(in), sclk(clock)
DigitalOut cs; // cs (the chip select signal)
DigitalOut myled1(LED1),myled2(LED2);
Timer t;
// For SPI
int DAread(int channel)
{
int command_high=0x06|((channel&0x04)>>2);
int command_low=(channel&0x03)<<14;
__disable_irq(); // 割り込み禁止
cs = 0;
spi.write(command_high);
int resultbyte=spi.write(command_low) & 0xfff;
cs = 1;
__enable_irq(); // 割り込み許可
return(resultbyte);
}
class SPI_TRP105FS
{
TRP105FS trp(5);
unsigned int channel;
void setSample(unsigned short arg_x) {
trp.setSample(arg_x, (unsigned short)DAread(channel));
}
void calibrate(){
trp.calibrate();
}
unsigned short get
}
TRP105FS senseor[8];
int main() {
// Setup the spi for 7 bit data, high steady state clock,
// second edge capture, with a 1MHz clock rate
spi.format(16,0);
spi.frequency(1000000);
myled1 = 1;
//pc.printf("start\n");
pc.printf("\nload save-data or calibration[l/c]>");
if(pc.getc() == 'l'){
pc.printf("\n");
//sensor.loadSetting();
sensor0.loadSetting("savedata.log");
}
else {
pc.printf("\n");
sensor0.calibrateSensor();
sensor0.printOutData();
sensor0.saveSetting("savedata.log");
}
myled2 = 1;
unsigned short dst;
while(1) {
t.start();
dst=sensor0.getDistance();
t.stop();
pc.printf("dst:%d(%f s)\n",dst, t.read());
t.reset();
//pc.printf("vol:%d",g_Sensor_Voltage.read_u16());
pc.printf("vol:%d",DAread(0));
wait(0.5);
pc.putc('\n');
if(pc.readable())if(pc.getc() == 'q') break;
}/*
while(1){
myled2 = 1;
pc.printf("vol:%d\n",DAread(1));
}*/
myled1 = myled2 = 0;
}