test 4D7S + HC-SR04 + NUCLEO-F103RB

Dependencies:   ArduinoFB SRF05 mbed

Files at this revision

API Documentation at this revision

Comitter:
fblanc
Date:
Thu Feb 12 10:26:36 2015 +0000
Child:
1:0f0f31f25bbd
Commit message:
ok sfr04+4D7S

Changed in this revision

ArduinoFB.lib Show annotated file Show diff for this revision Revisions of this file
SRF05.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ArduinoFB.lib	Thu Feb 12 10:26:36 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/rbohne/code/ArduinoHAL/#52ed7aa62e95
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SRF05.lib	Thu Feb 12 10:26:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/SRF05/#e758665e072c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 12 10:26:36 2015 +0000
@@ -0,0 +1,87 @@
+
+#include "SRF05.h"
+#include "Arduino.h"
+
+SRF05 srf(D6, D5);//trig;echo
+
+//*******************************************************************************
+//----------------本例程仅供学习使用,未经作者允许,不得用于其他用途。-----------
+//------------------------版权所有,仿冒必究!-----------------------------------
+//----------------1.开发环境:Arduino IDE-----------------------------------------
+//----------------2.测试使用开发板型号:Arduino Leonardo or Arduino UNO R3-------
+//----------------3.单片机使用晶振:16M------------------------------------------
+//----------------4.淘宝网址:http://xmdzpj.taobao.com---------------------------
+//----------------5.作者:真红炎神---------------------------------------------
+//*******************************************************************************/
+
+int latchPin = 4;
+int clockPin =7;
+int dataPin = 8; //这里定义了那三个脚
+
+unsigned char Dis_table[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};    //LED状态显示的变量
+unsigned char Dis_buf[]   = {0xF1,0xF2,0xF4,0xF8};
+unsigned char disbuff[]  =  {0, 0, 0, 0};
+
+
+void setup ()
+{
+  pinMode(latchPin,OUTPUT);
+  pinMode(clockPin,OUTPUT);
+  pinMode(dataPin,OUTPUT); //让三个脚都是输出状态
+
+}
+
+void display()
+{
+  for(char i=0; i<=3; i++)//扫描四个数码管
+  {
+    digitalWrite(latchPin,LOW); //将ST_CP口上面加低电平让芯片准备好接收数据
+    if(i==1)
+    {
+    shiftOut(dataPin,clockPin,MSBFIRST,Dis_table[disbuff[i]]&0x7F); //发送显示码
+    }
+    else
+    shiftOut(dataPin,clockPin,MSBFIRST,Dis_table[disbuff[i]]);
+    shiftOut(dataPin,clockPin,MSBFIRST,Dis_buf[i] );  //发送通值                                                    
+    //串行数据输入引脚为dataPin,时钟引脚为clockPin,执行MSB有限发送,发送数据table[i]
+    digitalWrite(latchPin,HIGH); //将ST_CP这个针脚恢复到高电平
+    delay(2);               //延时2ms 
+  }
+  
+}
+
+void loop()
+{
+  
+  float val;
+   val=srf*100;
+   /*
+  unsigned char t=((val%1000)/100);
+  
+  disbuff[0]= (unsigned char)(val/1000);
+  disbuff[1]= (unsigned char)((val%1000)/100);
+  disbuff[2]= (unsigned char)((val%100)/10);
+  */
+  disbuff[0]= (unsigned char)(val/1000);
+  disbuff[1]= (val/100)-disbuff[0]*10;
+  disbuff[2]= (val/10)-(disbuff[0]*100+disbuff[1]*10);
+  disbuff[3]= 0;
+
+  for(char time=0;time<30;time++)  //显示30次,当作延时,以免读取过快
+ { 
+  display();
+ }
+}
+
+
+
+
+main()
+{
+    setup();
+    while(1)
+    {
+        loop();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Feb 12 10:26:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa
\ No newline at end of file