This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
de:examples:sensor:ir_distance [2012/03/20 14:56] – wittkoepper | de:examples:sensor:ir_distance [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 53: | Line 53: | ||
d = 5461 / (ADC - 17) - 2 | d = 5461 / (ADC - 17) - 2 | ||
- | Diese Formel kann man mit 16-Bit | + | Diese Formel kann mit 16-Bit |
- | Es folgt die Funktion | + | Nachfolgend ist die Funktion |
<code c> | <code c> | ||
// | // | ||
- | // The structure of the parameters of the IR distance sensors | + | // Die Struktur der Parameter des Infrarot-Entfernungsmessers |
// | // | ||
typedef const struct | typedef const struct | ||
Line 71: | Line 71: | ||
// | // | ||
- | // The object of the parameters of GP2Y0A21YK | + | // Die Parametereigenschaften des GP2Y0A21YK |
// | // | ||
const ir_distance_sensor GP2Y0A21YK = { 5461, -17, 2 }; | const ir_distance_sensor GP2Y0A21YK = { 5461, -17, 2 }; | ||
// | // | ||
- | // Converting the values of the IR distance sensor to centimeters | + | // Konvertieren der Werte des Infrarot-Entfernungsmessers in Centimeter |
- | // Returns | + | // Gibt -1 aus, wenn die Konvertierung nicht erfolgreich war |
// | // | ||
signed short ir_distance_calculate_cm(ir_distance_sensor sensor, | signed short ir_distance_calculate_cm(ir_distance_sensor sensor, | ||
Line 91: | Line 91: | ||
</ | </ | ||
- | Um eine Konversion zu machen | + | Zur Durchführung der Konvertierung |
<code c> | <code c> | ||
// | // | ||
- | // The example program of the IR distance sensor of the HomeLab | + | // Beispielprogramm des Infrarot-Entfernungsmessers des HomeLab |
- | // Measured results | + | // Die in Centimetern gemessenen Ergebnisse werden auf dem LCD abgebildet |
// | // | ||
#include < | #include < | ||
Line 105: | Line 105: | ||
// | // | ||
- | // Main program | + | // Hauptprogramm |
// | // | ||
int main(void) | int main(void) | ||
Line 113: | Line 113: | ||
char text[16]; | char text[16]; | ||
- | // Initialization of LCD | + | // External sensor selection |
+ | pin ex_sensors = PIN(G, 0); | ||
+ | pin_setup_output(ex_sensors); | ||
+ | pin_set(ex_sensors); | ||
+ | |||
+ | // Initialisierung des LCD | ||
lcd_alpha_init(LCD_ALPHA_DISP_ON); | lcd_alpha_init(LCD_ALPHA_DISP_ON); | ||
- | // Clearing the LCD | + | // Löschen des LCD |
lcd_alpha_clear(); | lcd_alpha_clear(); | ||
- | // Name of the program | + | // Name des Programms |
lcd_alpha_write_string(" | lcd_alpha_write_string(" | ||
- | // Setup of the ADC | + | // Installation des ADC |
adc_init(ADC_REF_AVCC, | adc_init(ADC_REF_AVCC, | ||
- | // Endless loop | + | // Endlosschleife |
while (true) | while (true) | ||
{ | { | ||
- | // Reading the 4 times rounded value of the output voltage of the sensor | + | // Auslesen des viermal gerundeten Wertes der Outputspannung des Sensors |
value = adc_get_average_value(0, | value = adc_get_average_value(0, | ||
- | // Conversing | + | // Konvertieren des ADC-Wertes in Entfernung |
distance = ir_distance_calculate_cm(GP2Y0A21YK, | distance = ir_distance_calculate_cm(GP2Y0A21YK, | ||
- | // Was the calculation successful? | + | // War die Berechnung erfolgreich? |
if (distance >= 0) | if (distance >= 0) | ||
{ | { | ||
- | // Conversing distance to text | + | // Konvertieren von Entfernung in Text |
sprintf(text, | sprintf(text, | ||
} | } | ||
else | else | ||
{ | { | ||
- | // Creating the text for unknown distance | + | // Text für eine unbekannte Entfernung erzeugen |
sprintf(text, | sprintf(text, | ||
} | } | ||
- | // Displaying the text in the beginning of the second row on the LCD | + | // Anzeige des Textes am Anfang der zweiten Zeile auf dem LCD |
lcd_alpha_goto_xy(0, | lcd_alpha_goto_xy(0, | ||
lcd_alpha_write_string(text); | lcd_alpha_write_string(text); | ||
Line 156: | Line 161: | ||
</ | </ | ||
- | ===== Extra materials | + | ===== Zusätzliches Material |
- | * {{: | + | * {{: |
- | * [[http:// | + | * [[http:// |