初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*
* Miltiple Ultrasonic Sensors
* Prints the distance read by many ultrasonic sensors in
* centimeters and inches. They are supported to four pins
* ultrasound sensors (liek HC-SC04) and three pins
* (like PING))) and Seeed Studio sensors).
*
* The circuit:
* * In this circuit there is an ultrasonic module HC-SC04,
* PING))) and a Seeed Studio (4 pins, 3 pins, 3 pins,
* respectively), attached to digital pins as follows:
* --------------------- --------------------- -------------------
* | HC-SC04 | Arduino | | PING))) | Arduino | | Seeed | Arduino |
* --------------------- --------------------- -------------------
* | Vcc | 5V | | Vcc | 5V | | Vcc | 5V |
* | Trig | 12 | AND | SIG | 10 | AND | SIG | 8 |
* | Echo | 13 | | Gnd | GND | | Gnd | GND |
* | Gnd | GND | --------------------- -------------------
* ---------------------
* Note: You do not obligatorily need to use the pins defined above
*
* By default, the distance returned by the read()
* method is in centimeters. To get the distance in inches,
* pass INC as a parameter.
* Example: ultrasonic.read(INC)
*
* created 3 Mar 2017
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 11 Jun 2018
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
*
* This example code is released into the MIT License.
*/
#include <Ultrasonic.h>
Ultrasonic ultrasonic1(12, 13); // An ultrasonic sensor HC-04
Ultrasonic ultrasonic2(10); // An ultrasonic sensor PING)))
Ultrasonic ultrasonic3(8); // An Seeed Studio ultrasonic sensor
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Sensor 01: ");
Serial.print(ultrasonic1.read()); // Prints the distance on the default unit (centimeters)
Serial.println("cm");
Serial.print("Sensor 02: ");
Serial.print(ultrasonic2.read(CM)); // Prints the distance making the unit explicit
Serial.println("cm");
Serial.print("Sensor 03: ");
Serial.print(ultrasonic3.read(INC)); // Prints the distance in inches
Serial.println("inc");
delay(1000);
}

View File

@@ -0,0 +1,49 @@
/*
* Timeout
* Prints the distance read by an ultrasonic sensor in
* centimeters and change the default timeout. They are
* supported to four pins ultrasound sensors (liek HC-SC04)
* and three pins (like PING))) and Seeed Studio sensors).
*
* The circuit:
* * Module HR-SC04 (four pins) or PING))) (and other with
* three pins), attached to digital pins as follows:
* --------------------- --------------------
* | HC-SC04 | Arduino | | 3 pins | Arduino |
* --------------------- --------------------
* | Vcc | 5V | | Vcc | 5V |
* | Trig | 12 | OR | SIG | 13 |
* | Echo | 13 | | Gnd | GND |
* | Gnd | GND | --------------------
* ---------------------
* Note: You do not obligatorily need to use the pins defined above
*
* By default, the distance returned by the read()
* method is in centimeters. To get the distance in inches,
* pass INC as a parameter.
* Example: ultrasonic.read(INC)
*
* created 11 Jun 2018
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
*
* This example code is released into the MIT License.
*/
#include <Ultrasonic.h>
/**
* Is possible set the timeout in the constructor, like:
* Ultrasonic ultrasonic(12, 13, 20000UL);
*/
Ultrasonic ultrasonic(12, 13);
void setup() {
Serial.begin(9600);
ultrasonic.setTimeout(40000UL);
}
void loop() {
Serial.print("Distance in CM: ");
Serial.println(ultrasonic.read());
delay(1000);
}

View File

@@ -0,0 +1,59 @@
/*
* Ultrasonic Simple
* Prints the distance read by an ultrasonic sensor in
* centimeters. They are supported to four pins ultrasound
* sensors (liek HC-SC04) and three pins (like PING)))
* and Seeed Studio sensors).
*
* The circuit:
* * Module HR-SC04 (four pins) or PING))) (and other with
* three pins), attached to digital pins as follows:
* --------------------- --------------------
* | HC-SC04 | Arduino | | 3 pins | Arduino |
* --------------------- --------------------
* | Vcc | 5V | | Vcc | 5V |
* | Trig | 12 | OR | SIG | 13 |
* | Echo | 13 | | Gnd | GND |
* | Gnd | GND | --------------------
* ---------------------
* Note: You do not obligatorily need to use the pins defined above
*
* By default, the distance returned by the read()
* method is in centimeters. To get the distance in inches,
* pass INC as a parameter.
* Example: ultrasonic.read(INC)
*
* created 3 Apr 2014
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 23 Jan 2017
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 03 Mar 2017
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
* modified 11 Jun 2018
* by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
*
* This example code is released into the MIT License.
*/
#include <Ultrasonic.h>
/*
* Pass as a parameter the trigger and echo pin, respectively,
* or only the signal pin (for sensors 3 pins), like:
* Ultrasonic ultrasonic(13);
*/
Ultrasonic ultrasonic(12, 13);
int distance;
void setup() {
Serial.begin(9600);
}
void loop() {
// Pass INC as a parameter to get the distance in inches
distance = ultrasonic.read();
Serial.print("Distance in CM: ");
Serial.println(distance);
delay(1000);
}