This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:examples:sensor:ultrasonic_distance [2015/11/10 12:18] – heikopikner | en:examples:sensor:ultrasonic_distance [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Ultrasonic distance sensor ====== | ====== Ultrasonic distance sensor ====== | ||
- | //Necessary knowledge: | + | //Necessary knowledge: |
+ | [HW] [[en: | ||
+ | [AVR] [[en: | ||
+ | [LIB] [[en: | ||
+ | [LIB] [[en: | ||
===== Theory ===== | ===== Theory ===== | ||
Line 21: | Line 25: | ||
<code c> | <code c> | ||
#define ULTRASONIC_SPEED_OF_SOUND 33000 // cm/s | #define ULTRASONIC_SPEED_OF_SOUND 33000 // cm/s | ||
- | |||
// Ultrasonic distance measuring | // Ultrasonic distance measuring | ||
- | unsigned short ultrasonic_measure_srf05(pin | + | unsigned short ultrasonic_measure_srf05(pin |
{ | { | ||
// Pin setup | // Pin setup | ||
Line 34: | Line 37: | ||
// Create trigger pulse | // Create trigger pulse | ||
- | pin_set(srf05); | + | pin_set(triggerecho); |
| | ||
// Reset timer | // Reset timer | ||
Line 82: | Line 85: | ||
</ | </ | ||
- | Presented function allows the user to choose the echo/ | + | Presented function allows the user to choose the echo/ |
<code c> | <code c> | ||
- | // | ||
// The example program of the ultrasonic distance sensor of the HomeLab | // The example program of the ultrasonic distance sensor of the HomeLab | ||
// Measuring the distance is blocking. | // Measuring the distance is blocking. | ||
- | // | ||
#include < | #include < | ||
#include < | #include < | ||
Line 95: | Line 96: | ||
#include < | #include < | ||
- | // | ||
// Pins of ultrasonic sensor | // Pins of ultrasonic sensor | ||
// Robotic HomeLab II | // Robotic HomeLab II | ||
- | pin pin_pin_trigger_echo = PIN(F, 2); | + | //pin pin_pin_trigger_echo = PIN(F, 2); |
// Robotic HomeLab III | // Robotic HomeLab III | ||
Line 124: | Line 124: | ||
// Line selection | // Line selection | ||
- | lcd_gfx_goto_char_xy(1, | + | lcd_gfx_goto_char_xy(1, |
// Name of the program | // Name of the program | ||
Line 133: | Line 133: | ||
// Endless loop. | // Endless loop. | ||
- | while (true) | + | while (1) |
{ | { | ||
// Measuring | // Measuring | ||
Line 142: | Line 142: | ||
{ | { | ||
// converting the distance to text. | // converting the distance to text. | ||
- | sprintf(text, | + | sprintf(text, |
} | } | ||
// Were there errors during the measuring ? | // Were there errors during the measuring ? | ||
Line 160: | Line 160: | ||
} | } | ||
</ | </ | ||
- | If older type sensor | + | To make sure that the ultrasonic |