From 9af5bc8463b06a2824a04d68ce7b0178001b9a77 Mon Sep 17 00:00:00 2001 From: Sanyog Date: Sat, 30 Nov 2024 03:36:37 +0530 Subject: [PATCH] Add Comments --- main.c | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/main.c b/main.c index 3b4f990..c918f71 100644 --- a/main.c +++ b/main.c @@ -49,30 +49,36 @@ void GPIO_PORT_B_init(void) UART1_IM_R |= 0x10; NVIC_EN0_R |= (1 << 6); } -// Control LEDs based on speed -void control_leds_based_on_speed(float speed_kmh) { - // Clear all LED bits (assuming LEDs are connected to bits 1, 2, and 3) - GPIO_PORTF_DATA_R &= 0x00; - // Determine which 5 km/h range the speed falls into - if (speed_kmh >= 0.0 && speed_kmh < 10.0) { - // Range 0-10 km/h - GPIO_PORTF_DATA_R |= 0x08; // Red LED - } else if (speed_kmh >= 10.0 && speed_kmh < 20.0) { - // Range 10-20 km/h - GPIO_PORTF_DATA_R |= 0x0C; // Blue LED - } else if (speed_kmh >= 20.0 && speed_kmh < 30.0) { - // Range 20-30 km/h - GPIO_PORTF_DATA_R |= 0x04; // Green LED - } else if (speed_kmh >= 30.0 && speed_kmh < 40.0) { - // Range 30-40 km/h - GPIO_PORTF_DATA_R |= 0x06; // Yellow LED (Red + Green) - } else if (speed_kmh >= 40.0 && speed_kmh < 50.0) { - // Range 40-50 km/h - GPIO_PORTF_DATA_R |= 0x02; // Blue LED - } else { - // Above 50 km/h - GPIO_PORTF_DATA_R |= 0x0E; // Maximum LED (Red + Blue + Green) +void control_leds_based_on_speed(float speed_kmh) // Control LEDs based on speed +{ + + GPIO_PORTF_DATA_R &= 0x00; // Clear all LED bits (assuming LEDs are connected to bits 1, 2, and 3) + + + if (speed_kmh >= 0.0 && speed_kmh < 10.0) // Range 0-10 km/h + { + GPIO_PORTF_DATA_R |= 0x08; // Red LED + } + else if (speed_kmh >= 10.0 && speed_kmh < 20.0) // Range 10-20 km/h + { + GPIO_PORTF_DATA_R |= 0x0C; // Blue LED + } + else if (speed_kmh >= 20.0 && speed_kmh < 30.0) // Range 20-30 km/h + { + GPIO_PORTF_DATA_R |= 0x04; // Green LED + } + else if (speed_kmh >= 30.0 && speed_kmh < 40.0) // Range 30-40 km/h + { + GPIO_PORTF_DATA_R |= 0x06; // Yellow LED (Red + Green) + } + else if (speed_kmh >= 40.0 && speed_kmh < 50.0) // Range 40-50 km/h + { + GPIO_PORTF_DATA_R |= 0x02; // Blue LED + } + else // Above 50 km/h + { + GPIO_PORTF_DATA_R |= 0x0E; // Maximum LED (Red + Blue + Green) } }