/********************************
Student Name:
Man Lai Sun 230226334
Leung Kai Chung 230268664
Leung Wing Kit 230279168
Liu Kwok Kin 230329557
Class: EG524403-1A
Student number: 230268664
Filename: sketch.ino
Demo URL: https://wokwi.com/projects/383445472129549313
*/
#include "pin_map.h"
#include "traffic_light.h"
TrafficLight* lights[2]; // Two set of traffic light
TaskHandle_t handler = NULL; // The new task to 'Dic' the buzzer
void setup() {
/******** Init Buzzer Pin **********/
pinMode(A_BUZZER_PIN, OUTPUT);
pinMode(B_BUZZER_PIN, OUTPUT);
ledcSetup(0, 100, 8);
ledcAttachPin ( A_BUZZER_PIN, 0 );
ledcSetup(1, 100, 8);
ledcAttachPin ( B_BUZZER_PIN, 1 );
/***********************************/
lights[0] = new TrafficLight (
A_RED_PIN,
A_GREEN_PIN,
A_TRIGG_PIN,
0 );
lights[1] = new TrafficLight (
B_RED_PIN,
B_GREEN_PIN,
B_TRIGG_PIN,
1 );
}
void loop() {
int side = TrafficLight::GetSide();
xTaskCreate(
TrafficLight::BuzzerOnRed, // Function that should be called
"buzzerInRed", // Task name
1000, // Stack
NULL, // Param
1, // priority
&handler // Task handle
);
lights[side] -> toRed ( );
lights[!side] -> toGreen ( );
delay ( 5000 ) ;
lights[!side] -> blinkGreen ( );
lights[side] -> trigg ( );
lights[!side] -> blinkGreen ( );
lights[side] -> trigg ( );
if (handler != NULL) {
vTaskDelete(handler);
handler = NULL;
}
ledcWriteTone(side, 0);
TrafficLight::changeSize() ; // change the light side
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4