Added the stoplight task (part 1)

This commit is contained in:
_N0x 2021-11-11 01:36:35 +01:00
parent 663d817b11
commit 082bc7e986

View File

@ -18,6 +18,13 @@ void task1 (void);
void task2 (void);
void task3 (void);
/* enums */
enum{
S1_GREEN, S1_YELLOW, S1_RED, S1_RED_YELLOW,
S2_GREEN, S2_YELLOW, S2_RED, S2_RED_YELLOW,
INIT,
} StoplightState = INIT; /* Emus for the stoplight task (task 3) */
/* global variables */
volatile int g_counter = 0;
int g_ledStatus = 0;
@ -38,10 +45,10 @@ main (void)
while (1)
{
buttonTest();
//buttonTest();
//task1();
//task2();
//task3();
task3();
}
}
@ -107,8 +114,87 @@ task2 (void)
}
}
void
/* Task 3 */
void
task3 (void)
{
// beep boop
/* Programmieren eine Ampelsteuerung auf einer Straßenkreuzung */
/*
int delayShort = 5000;
int delayLong = 30000;
//*/
int delayShort = 2500;
int delayLong = 7500;
/* Stoplight and the corresponding Leds
| GREEN | YELLOW | RED
----------------------------------
SL 1 | Led1 | Led4 | Led6
SL 2 | Led2 | Led5 | Led7
*/
switch(StoplightState){
case INIT:
Led1_On(); // Set stoplight 1 to green
Led2_Off();
Led3_Off();
Led4_Off();
Led5_Off();
Led6_Off();
Led7_On(); // Set stoplight 2 to red
Led8_Off();
StoplightState = S1_YELLOW;
case S1_YELLOW: // Set stoplight 2 to yellow
_delay_ms(delayLong);
Led1_Off();
Led4_On();
StoplightState = S1_RED;
case S1_RED: // Set stoplight 2 to red
_delay_ms(delayShort);
Led4_Off();
Led6_On();
StoplightState = S2_RED_YELLOW;
case S2_RED_YELLOW:
_delay_ms(delayShort);
Led5_On();
Led7_On();
StoplightState = S2_GREEN;
case S2_GREEN:
_delay_ms(delayShort);
Led5_Off();
Led7_Off();
Led2_On();
StoplightState = S2_YELLOW;
case S2_YELLOW:
_delay_ms(delayLong);
Led2_Off();
Led5_On();
StoplightState = S2_RED;
case S2_RED:
_delay_ms(delayShort);
Led5_Off();
Led7_On();
StoplightState = S1_RED_YELLOW;
case S1_RED_YELLOW:
_delay_ms(delayShort);
Led4_On();
Led6_On();
StoplightState = S1_GREEN;
case S1_GREEN:
_delay_ms(delayShort);
Led4_Off();
Led6_Off();
Led1_On();
StoplightState = S1_YELLOW;
}
}