From 13be37ba8257d76a8e806a63d380ee4e5e73f261 Mon Sep 17 00:00:00 2001 From: Uttam Bhavimani Bhavimani Date: Fri, 29 Nov 2024 14:54:00 +0530 Subject: [PATCH] Update Control LEDs based on speed logic --- main.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.c b/main.c index fbe159d..ec92c51 100644 --- a/main.c +++ b/main.c @@ -34,6 +34,32 @@ 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) + } +}