This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:software:homelab:library:module:sensor [2010/03/29 17:40] – Helen | en:software:homelab:library:module:sensor [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
//Related to: [HW] [[en: | //Related to: [HW] [[en: | ||
- | This library contains functions to use different sensors in Homelab | + | This library contains functions to use different sensors in the HomeLab |
- | ===== Data types ===== | + | ===== Data Types ===== |
* **// | * **// | ||
Line 31: | Line 31: | ||
* Returns distance in centimeters or -1 if it cannot be calculated. | * Returns distance in centimeters or -1 if it cannot be calculated. | ||
- | * **// | + | * **// |
- | Measures distance with ultrasonic distance sensor. | + | Measures distance with ultrasonic distance sensor |
* //trigger// - Trigger pin variable. | * //trigger// - Trigger pin variable. | ||
* //echo// - Echo pin variable. | * //echo// - Echo pin variable. | ||
+ | * Returns distance in centimeters or 0 when measuring failed. | ||
+ | * **// | ||
+ | Measures distance with ultrasonic distance sensor SRF05 in one wire regime. Function generates a trigger pulse on the pin and measures the time of echo pulse on the same pin. Distance is calculated from the time. Function expects a 14.7456 MHz clock frequency. Measuring may take up to 36 ms. Parameters: | ||
+ | * // | ||
* Returns distance in centimeters or 0 when measuring failed. | * Returns distance in centimeters or 0 when measuring failed. | ||
===== Example ===== | ===== Example ===== | ||
- | The following program demonstrates usage of IR and ultrasonic distance | + | The following program demonstrates usage of IR and ultrasonic distance |
<code c> | <code c> | ||
Line 45: | Line 49: | ||
// Ultrasonic distance sensor control pins. | // Ultrasonic distance sensor control pins. | ||
- | pin pin_trigger = PIN(G, 1); | + | pin pin_triggerecho |
- | pin pin_echo | + | |
int main(void) | int main(void) | ||
Line 57: | Line 60: | ||
// Measuring with ultrasonic distance sensor. | // Measuring with ultrasonic distance sensor. | ||
- | distance = ultrasonic_measure(pin_trigger, | + | distance = ultrasonic_measure_srf05(pin_triggerecho); |
} | } | ||
</ | </ | ||
- |