-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceDriverSet_xxx0_UltrasonicSensor.cpp
More file actions
56 lines (48 loc) · 1.39 KB
/
DeviceDriverSet_xxx0_UltrasonicSensor.cpp
File metadata and controls
56 lines (48 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* @Author: ELEGOO
* @Date: 2019-10-22 11:59:09
* @LastEditTime: 2020-06-12 16:36:20
* @LastEditors: Changhua
* @Description: conqueror robot tank
* @FilePath:
*/
#include "DeviceDriverSet_xxx0_UltrasonicSensor.h"
/*ULTRASONIC*/
//#include <NewPing.h>
// NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void DeviceDriverSet_ULTRASONIC::DeviceDriverSet_ULTRASONIC_Init(void)
{
pinMode(ECHO_PIN, INPUT); //Ultrasonic module initialization
pinMode(TRIG_PIN, OUTPUT);
}
/*
void DeviceDriverSet_ULTRASONIC::DeviceDriverSet_ULTRASONIC_Get(uint16_t *ULTRASONIC_Get out)
{
unsigned int tempda_x = 0;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
tempda_x = ((unsigned int)pulseIn(ECHO_PIN, HIGH) / 58);
*ULTRASONIC_Get = tempda_x;
// sonar.ping() / US_ROUNDTRIP_CM; // Send ping, get ping time in microseconds (uS).
}
*/
unsigned int DeviceDriverSet_ULTRASONIC::DeviceDriverSet_ULTRASONIC_Get(void)
{
unsigned int tempda = 0;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
tempda = ((unsigned int)pulseIn(ECHO_PIN, HIGH) / 58);
// if (tempda_x > 50)
// {
// tempda_x = 50;
// }
// // return tempda;
// return tempda_x;
return tempda;
}