SHARE
TWEET

Untitled

a guest May 25th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define r_ns 2
  2. #define y_ns 3
  3. #define g_ns 4
  4.  
  5. #define r_ew 5
  6. #define y_ew 6
  7. #define g_ew 7
  8.  
  9. #define sensor_east 10
  10. #define sensor_west 11
  11.  
  12. #define time_base 1000
  13.  
  14. void setup() {
  15.   // put your setup code here, to run once:
  16.   pinMode(r_ns, OUTPUT);
  17.   pinMode(y_ns, OUTPUT);
  18.   pinMode(g_ns, OUTPUT);
  19.   pinMode(r_ew, OUTPUT);
  20.   pinMode(y_ew, OUTPUT);
  21.   pinMode(g_ew, OUTPUT);
  22. }
  23.  
  24. void ChangeLedValue(byte number){
  25.   digitalWrite(r_ns, bitRead(number,5));
  26.   digitalWrite(y_ns, bitRead(number,4));
  27.   digitalWrite(g_ns, bitRead(number,3));
  28.   digitalWrite(r_ew, bitRead(number,2));
  29.   digitalWrite(y_ew, bitRead(number,1));
  30.   digitalWrite(g_ew, bitRead(number,0));
  31. }
  32. void LightSequence(){
  33.   ChangeLedValue(B001100);
  34.   delay(time_base * 10);
  35.  
  36.   ChangeLedValue(B010100);
  37.   delay(time_base * 1);
  38.  
  39.   ChangeLedValue(B100100);
  40.   delay(time_base * 1);
  41.  
  42.   ChangeLedValue(B100001);
  43.   delay(time_base * 5);
  44.  
  45.   ChangeLedValue(B100010);
  46.   delay(time_base * 1);
  47.  
  48.   ChangeLedValue(B100100);
  49.   delay(time_base * 1);
  50. }
  51.  
  52. void loop() {
  53.   // put your main code here, to run repeatedly:
  54.   if(digitalRead(10) == 1 || digitalRead(11) == 1)
  55.     i = i + 1;
  56.     delay(20);
  57.   else
  58.     i = 0;
  59.   if(i == 50)
  60.     LightSequence();
  61.   }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top