1、 STM32F410在mbed的条件下使用里的arduino接口对应如下:
2、对应的morphor接口如下,
3、 导入驱动库如下
4. 定义引脚
HCSR04::HCSR04(PinName trigger, PinName echo) : _t(trigger), _e(echo) {
wait(0.1);
}
5、 程序如下,
#include "mbed.h"
#include "HCSR04.h"
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
HCSR04 sonar(D12, D13);
int main()
{
int i = 1;
float tmp=0;
pc.printf("Hello World !\n");
tmp=sonar.getCm();
pc.printf("distance=%d",tmp);
while(1) {
wait(1);
//pc.printf("This program runs since %d seconds.\n", i++);
tmp=sonar.getCm();
pc.printf("distance=%d cm\n",tmp);
myled = !myled;
}
}