Add Comments
This commit is contained in:
parent
efea960180
commit
9af5bc8463
40
main.c
40
main.c
|
@ -49,29 +49,35 @@ 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 &= 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
|
GPIO_PORTF_DATA_R |= 0x08; // Red LED
|
||||||
} else if (speed_kmh >= 10.0 && speed_kmh < 20.0) {
|
}
|
||||||
// Range 10-20 km/h
|
else if (speed_kmh >= 10.0 && speed_kmh < 20.0) // Range 10-20 km/h
|
||||||
|
{
|
||||||
GPIO_PORTF_DATA_R |= 0x0C; // Blue LED
|
GPIO_PORTF_DATA_R |= 0x0C; // Blue LED
|
||||||
} else if (speed_kmh >= 20.0 && speed_kmh < 30.0) {
|
}
|
||||||
// Range 20-30 km/h
|
else if (speed_kmh >= 20.0 && speed_kmh < 30.0) // Range 20-30 km/h
|
||||||
|
{
|
||||||
GPIO_PORTF_DATA_R |= 0x04; // Green LED
|
GPIO_PORTF_DATA_R |= 0x04; // Green LED
|
||||||
} else if (speed_kmh >= 30.0 && speed_kmh < 40.0) {
|
}
|
||||||
// Range 30-40 km/h
|
else if (speed_kmh >= 30.0 && speed_kmh < 40.0) // Range 30-40 km/h
|
||||||
|
{
|
||||||
GPIO_PORTF_DATA_R |= 0x06; // Yellow LED (Red + Green)
|
GPIO_PORTF_DATA_R |= 0x06; // Yellow LED (Red + Green)
|
||||||
} else if (speed_kmh >= 40.0 && speed_kmh < 50.0) {
|
}
|
||||||
// Range 40-50 km/h
|
else if (speed_kmh >= 40.0 && speed_kmh < 50.0) // Range 40-50 km/h
|
||||||
|
{
|
||||||
GPIO_PORTF_DATA_R |= 0x02; // Blue LED
|
GPIO_PORTF_DATA_R |= 0x02; // Blue LED
|
||||||
} else {
|
}
|
||||||
// Above 50 km/h
|
else // Above 50 km/h
|
||||||
|
{
|
||||||
GPIO_PORTF_DATA_R |= 0x0E; // Maximum LED (Red + Blue + Green)
|
GPIO_PORTF_DATA_R |= 0x0E; // Maximum LED (Red + Blue + Green)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue