Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PIN_A 0
- #define PIN_B 1
- #define PIN_C 2
- #define PIN_D 4
- const int pause = 500;
- void setup()
- {
- // first set all pins to input, or high impedance
- // (not strictly necessary as all pins are inputs by default)
- pinMode(PIN_A, INPUT);
- pinMode(PIN_B, INPUT);
- pinMode(PIN_C, INPUT);
- pinMode(PIN_D, INPUT);
- }
- void loop()
- {
- // run through a sample loop, lighting each LED
- // in turn and holding for half a second.
- set_pins(PIN_A, PIN_B);
- delay(pause);
- set_pins(PIN_B, PIN_A);
- delay(pause);
- set_pins(PIN_A, PIN_C);
- delay(pause);
- set_pins(PIN_C, PIN_A);
- delay(pause);
- set_pins(PIN_A, PIN_D);
- delay(pause);
- set_pins(PIN_D, PIN_A);
- delay(pause);
- set_pins(PIN_B, PIN_C);
- delay(pause);
- set_pins(PIN_C, PIN_B);
- delay(pause);
- set_pins(PIN_B, PIN_D);
- delay(pause);
- set_pins(PIN_D, PIN_B);
- delay(pause);
- set_pins(PIN_C, PIN_D);
- delay(pause);
- set_pins(PIN_D, PIN_C);
- delay(pause);
- }
- void set_pins(int high_pin, int low_pin)
- {
- // reset all the pins
- reset_pins();
- // set the high and low pins to output
- pinMode(high_pin, OUTPUT);
- pinMode(low_pin, OUTPUT);
- // set high pin to logic high, low to logic low
- digitalWrite(high_pin, HIGH);
- digitalWrite(low_pin, LOW);
- }
- void reset_pins()
- {
- // start by ensuring all pins are at input and low
- pinMode(PIN_A, INPUT);
- pinMode(PIN_B, INPUT);
- pinMode(PIN_C, INPUT);
- pinMode(PIN_D, INPUT);
- digitalWrite(PIN_A, LOW);
- digitalWrite(PIN_B, LOW);
- digitalWrite(PIN_C, LOW);
- digitalWrite(PIN_D, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement