Add Comments

This commit is contained in:
Sanyog Nevase Nevase 2024-11-30 03:36:37 +05:30
parent efea960180
commit 9af5bc8463
1 changed files with 29 additions and 23 deletions

52
main.c
View File

@ -49,30 +49,36 @@ void GPIO_PORT_B_init(void)
UART1_IM_R |= 0x10; UART1_IM_R |= 0x10;
NVIC_EN0_R |= (1 << 6); 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 void control_leds_based_on_speed(float speed_kmh) // Control LEDs based on speed
if (speed_kmh >= 0.0 && speed_kmh < 10.0) { {
// Range 0-10 km/h
GPIO_PORTF_DATA_R |= 0x08; // Red LED GPIO_PORTF_DATA_R &= 0x00; // Clear all LED bits (assuming LEDs are connected to bits 1, 2, and 3)
} else if (speed_kmh >= 10.0 && speed_kmh < 20.0) {
// Range 10-20 km/h
GPIO_PORTF_DATA_R |= 0x0C; // Blue LED if (speed_kmh >= 0.0 && speed_kmh < 10.0) // Range 0-10 km/h
} else if (speed_kmh >= 20.0 && speed_kmh < 30.0) { {
// Range 20-30 km/h GPIO_PORTF_DATA_R |= 0x08; // Red LED
GPIO_PORTF_DATA_R |= 0x04; // Green LED }
} else if (speed_kmh >= 30.0 && speed_kmh < 40.0) { else if (speed_kmh >= 10.0 && speed_kmh < 20.0) // Range 10-20 km/h
// Range 30-40 km/h {
GPIO_PORTF_DATA_R |= 0x06; // Yellow LED (Red + Green) GPIO_PORTF_DATA_R |= 0x0C; // Blue LED
} else if (speed_kmh >= 40.0 && speed_kmh < 50.0) { }
// Range 40-50 km/h else if (speed_kmh >= 20.0 && speed_kmh < 30.0) // Range 20-30 km/h
GPIO_PORTF_DATA_R |= 0x02; // Blue LED {
} else { GPIO_PORTF_DATA_R |= 0x04; // Green LED
// Above 50 km/h }
GPIO_PORTF_DATA_R |= 0x0E; // Maximum LED (Red + Blue + Green) 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)
} }
} }