Advertisement
Drakkheen

Untitled

Jun 10th, 2021
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define PIN_A 0
  2. #define PIN_B 1
  3. #define PIN_C 2
  4. #define PIN_D 4
  5. const int pause = 500;
  6.  
  7. void setup()
  8. {
  9.   // first set all pins to input, or high impedance
  10.   // (not strictly necessary as all pins are inputs by default)
  11.   pinMode(PIN_A, INPUT);
  12.   pinMode(PIN_B, INPUT);
  13.   pinMode(PIN_C, INPUT);
  14.   pinMode(PIN_D, INPUT);
  15. }
  16.  
  17. void loop()
  18. {
  19.   // run through a sample loop, lighting each LED
  20.  
  21.   // in turn and holding for half a second.
  22.   set_pins(PIN_A, PIN_B);
  23.   delay(pause);
  24.  
  25.   set_pins(PIN_B, PIN_A);
  26.   delay(pause);
  27.  
  28.   set_pins(PIN_A, PIN_C);
  29.   delay(pause);
  30.  
  31.   set_pins(PIN_C, PIN_A);
  32.   delay(pause);
  33.  
  34.   set_pins(PIN_A, PIN_D);
  35.   delay(pause);
  36.  
  37.   set_pins(PIN_D, PIN_A);
  38.   delay(pause);
  39.  
  40.   set_pins(PIN_B, PIN_C);
  41.   delay(pause);
  42.  
  43.   set_pins(PIN_C, PIN_B);
  44.   delay(pause);
  45.  
  46.   set_pins(PIN_B, PIN_D);
  47.   delay(pause);
  48.  
  49.   set_pins(PIN_D, PIN_B);
  50.   delay(pause);
  51.  
  52.     set_pins(PIN_C, PIN_D);
  53.   delay(pause);
  54.  
  55.     set_pins(PIN_D, PIN_C);
  56.   delay(pause);
  57.  
  58. }
  59.  
  60. void set_pins(int high_pin, int low_pin)
  61. {
  62.   // reset all the pins
  63.   reset_pins();
  64.  
  65.   // set the high and low pins to output
  66.   pinMode(high_pin, OUTPUT);
  67.   pinMode(low_pin, OUTPUT);
  68.  
  69.   // set high pin to logic high, low to logic low
  70.   digitalWrite(high_pin, HIGH);
  71.   digitalWrite(low_pin, LOW);
  72. }
  73.  
  74. void reset_pins()
  75. {
  76.   // start by ensuring all pins are at input and low
  77.   pinMode(PIN_A, INPUT);
  78.   pinMode(PIN_B, INPUT);
  79.   pinMode(PIN_C, INPUT);
  80.   pinMode(PIN_D, INPUT);
  81.  
  82.   digitalWrite(PIN_A, LOW);
  83.   digitalWrite(PIN_B, LOW);
  84.   digitalWrite(PIN_C, LOW);
  85.   digitalWrite(PIN_D, LOW);
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement