This commit is contained in:
Sem van der Hoeven
2021-04-06 15:19:00 +02:00
parent 4416e1fff4
commit 70c0079e7f
3 changed files with 15 additions and 2 deletions

View File

@@ -131,10 +131,18 @@ void lcd_write_int(int number)
lcd_write_string(str); lcd_write_string(str);
} }
void lcd_write_double(char prefix[], double number, char suffix[]) void lcd_write_double(char prefix[], float number, char suffix[])
{ {
int length = snprintf(NULL, 0, "%s: %.3f %s", prefix, number, suffix); int length = snprintf(NULL, 0, "%s: %.3f %s", prefix, number, suffix);
char str[length + 1]; char str[length + 1];
snprintf(str, length + 1, "%s: %.3f %s", prefix, number, suffix); snprintf(str, length + 1, "%s: %.3f %s", prefix, number, suffix);
lcd_write_string(str); lcd_write_string(str);
} }
void lcd_write_ultrasonic_value(float number)
{
int length = snprintf(NULL, 0, "%.3f CM", number);
char str[length + 1];
snprintf(str, length + 1, "%.3f CM", number);
lcd_write_string(str);
}

View File

@@ -41,6 +41,11 @@ void lcd_write_int(int number);
/************************************************************************/ /************************************************************************/
void lcd_write_double(char prefix[], double number, char suffix[]); void lcd_write_double(char prefix[], double number, char suffix[]);
/************************************************************************/
/* write ultrasonic reading on the lcd */
/************************************************************************/
void lcd_write_ultrasonic_value(float number);
#endif /* LCD_CONTROL_H_ */ #endif /* LCD_CONTROL_H_ */

View File

@@ -69,7 +69,7 @@ int main(void)
{ {
lcd_clear(); lcd_clear();
// set the ultrasonic value to the lcd. // set the ultrasonic value to the lcd.
lcd_write_int(ultrasonic_get_timer_dist()); lcd_write_ultrasonic_value(ultrasonic_get_timer_dist());
wait_ms(LCD_SET_DELAY); wait_ms(LCD_SET_DELAY);
} }