พื้นฐาน Embedded C - ตอนที่ 3
C Programming - Control Flow
1. Conditional Statements (if-else)
int16_t temperature = 28;
/* Simple if */
if (temperature > 30)
{
printf("Hot!\r\n");
}
/* if-else */
if (temperature > 30)
{
set_led_color(RED);
}
else
{
set_led_color(GREEN);
}
/* if-else if-else */
if (temperature > 35)
{
printf("Very Hot!\r\n");
set_led_color(RED);
}
else if (temperature > 30)
{
printf("Hot\r\n");
set_led_color(YELLOW);
}
else if (temperature < 15)
{
printf("Cold\r\n");
set_led_color(BLUE);
}
else
{
printf("Normal\r\n");
set_led_color(GREEN);
}2. Switch Statement
3. Loops
4. State Machine Pattern
Last updated
Was this helpful?