Home > other >  Seven lines of code to implement a ultrasonic rangefinder (Oled display)
Seven lines of code to implement a ultrasonic rangefinder (Oled display)

Time:11-17

one, foreword
Shineblink core development board (hereinafter referred to as the core of library functions to support US - 015 ultrasonic ranging sensors, so only need to call the two apis, ultrasonic ranging function can be realized,

PS: the Core with only five, six lines of code can be realized Wifi/Ble/NB/Lora/ThreadMesh/RFID/Eth/Usb/RS485/RS232 communication, and more than 30 sensors/more than 10 kinds of hardware peripherals/more than 10 kinds of Mcu internal functions, and these functions can be up to five kinds of random combination running at the same time,

2, production materials
Shineblink core development board a
An ultrasonic ranging sensor module
0.96 inch oled display a
TYPE00 a - 0000003 - f circuit boards, the circuit principle diagram and PCB source file, please download (AD engineering) in the network location address below:
https://yunpan.360.cn/surl_yP9fgP7LVGa


three, complete code
 LIB_0_96_OledConfig (" IIC1 ") 
LIB_US015Config ()
?

- began circulationWhile (GC (1)==true)
Do
- delay 200 milliseconds
LIB_DelayMs (200)

Flag, short=LIB_US015GetDistance ()
If flag==1 then
- display measuring distance
LIB_0_96_OledPuts (" 2 ", "1", the string. Format (short: % 4 DMM, short))
End
End


4, the production process & amp; Results show
Core development way is very elegant, with a notepad (or any other editor) open the Core development board of TF card. The main lua files, and then copy the code above to the main. The lua files can, because the Core built-in lua compiler, so without you having to do any processing, the Core can start work in accordance with the above code,

Below for after completion of assembly welding code running effect:


five, conclusion
The above code for every 0.2 seconds to update the display of an ultrasonic ranging sensor output value, more technical information about the Core, can visit http://shineblink.com to get to know,
  • Related