Update Control LEDs based on speed logic
This commit is contained in:
parent
2b539ed0b9
commit
13be37ba82
26
main.c
26
main.c
|
@ -34,6 +34,32 @@ 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
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue