Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unistd.h>
- using namespace std;
- #define NUM_THREADS 5
- struct Colors{
- bool red = 0;
- bool yellow = 0;
- bool green = 0;
- bool turn_left = 0;
- bool turn_right = 0;
- bool sensor_A = 0;
- bool sensor_B = 0;
- }lane_A, lane_B;
- void set_sensor_A(){
- // should receive signal from wherever
- }
- void set_sensor_B(){
- // should recieve signal from wherever
- }
- int main()
- {
- while(1){
- while(lane_A.sensor_A == 1 and lane_B.sensor_B == 1){
- lane_A.yellow = 0;
- lane_B.yellow = 0;
- // then both board should display yellow
- sleep(15);
- lane_A.red = 0;
- lane_B.red = 0;
- // then both board should display red and so on for the rest
- sleep(200);
- lane_A.turn_left = 1;
- lane_B.turn_right = 0;
- if(lane_A.sensor_B != 0 && lane_B.sensor_B != 0){
- break;
- }
- }
- lane_A.turn_left = 0;
- lane_B.green = 1;
- lane_B.turn_right = 0
- sleep(600);
- lane_A.yellow = 1;
- lane_B.yellow = 1;
- sleep(5);
- lane_A.red = 1;
- lane_B.red = 1;
- sleep(200);
- lane_B.turn_left = 1;
- lane_A.turn_right = 1;
- sleep(300);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement