Advertisement
Fourteen98

Untitled

Jun 17th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <unistd.h>
  4. using namespace std;
  5.  
  6. #define NUM_THREADS 5
  7. struct Colors{
  8.     bool red = 0;
  9.     bool yellow = 0;
  10.     bool green = 0;
  11.     bool turn_left = 0;
  12.     bool turn_right = 0;
  13.     bool sensor_A = 0;
  14.     bool sensor_B = 0;
  15.  
  16. }lane_A, lane_B;
  17.  
  18.  
  19. void set_sensor_A(){
  20.     // should receive signal from wherever
  21. }
  22.  
  23. void set_sensor_B(){
  24.     // should recieve signal from wherever
  25.  
  26. }
  27.  
  28.    
  29.  
  30. int main()
  31. {
  32.    
  33.    while(1){
  34.      
  35.            
  36.             while(lane_A.sensor_A == 1 and lane_B.sensor_B == 1){
  37.                 lane_A.yellow = 0;
  38.                 lane_B.yellow = 0;
  39.                 // then both board should display yellow
  40.                 sleep(15);
  41.                 lane_A.red = 0;
  42.                 lane_B.red = 0;
  43.                 // then both board should display red and so on for the rest
  44.                 sleep(200);
  45.                 lane_A.turn_left = 1;
  46.                 lane_B.turn_right = 0;
  47.                 if(lane_A.sensor_B != 0 && lane_B.sensor_B != 0){
  48.                     break;
  49.                 }
  50.             }
  51.            
  52.             lane_A.turn_left = 0;
  53.             lane_B.green = 1;
  54.             lane_B.turn_right = 0
  55.             sleep(600);
  56.            
  57.             lane_A.yellow = 1;
  58.             lane_B.yellow = 1;
  59.             sleep(5);
  60.            
  61.             lane_A.red = 1;
  62.             lane_B.red = 1;
  63.             sleep(200);
  64.            
  65.             lane_B.turn_left = 1;
  66.             lane_A.turn_right = 1;
  67.             sleep(300);
  68.            
  69.          
  70.         }
  71.    }
  72.    return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement