Created
February 5, 2016 00:33
-
-
Save th0mk/7bdb6816c661de38d42b to your computer and use it in GitHub Desktop.
Simple Arduino elevator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int button1Pin = 1; | |
const int button2Pin = 2; | |
const int button3Pin = 3; | |
const int button4Pin = 4; | |
const int button5Pin = 5; | |
const int led1Pin = 9; | |
const int led2Pin = 10; | |
const int led3Pin = 11; | |
const int led4Pin = 12; | |
const int led5Pin = 13; | |
int button1State = 0; | |
int button2State = 0; | |
int button3State = 0; | |
int button4State = 0; | |
int button5State = 0; | |
void setup() { | |
pinMode(button1Pin, INPUT); | |
pinMode(button2Pin, INPUT); | |
pinMode(button3Pin, INPUT); | |
pinMode(button4Pin, INPUT); | |
pinMode(button5Pin, INPUT); | |
pinMode(led1Pin, OUTPUT); | |
pinMode(led2Pin, OUTPUT); | |
pinMode(led3Pin, OUTPUT); | |
pinMode(led4Pin, OUTPUT); | |
pinMode(led5Pin, OUTPUT); | |
digitalWrite(led1Pin, HIGH); | |
} | |
void loop() { | |
button1State = digitalRead(button1Pin); | |
button2State = digitalRead(button2Pin); | |
button3State = digitalRead(button3Pin); | |
button4State = digitalRead(button4Pin); | |
button5State = digitalRead(button5Pin); | |
if (button5State == HIGH) { | |
for(int i=9; i < 13; i++){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led5Pin, HIGH); | |
delay(1000); | |
for(int i=13; i > 9; i--){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led1Pin, HIGH); | |
} | |
if (button4State == HIGH) { | |
for(int i=9; i < 12; i++){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led4Pin, HIGH); | |
delay(1000); | |
for(int i=12; i > 9; i--){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led1Pin, HIGH); | |
} | |
if (button3State == HIGH) { | |
for(int i=9; i < 11; i++){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led3Pin, HIGH); | |
delay(1000); | |
for(int i=11; i > 9; i--){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led1Pin, HIGH); | |
} | |
if (button2State == HIGH) { | |
for(int i=9; i < 10; i++){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led2Pin, HIGH); | |
delay(1000); | |
for(int i=10; i > 9; i--){ | |
digitalWrite(i, HIGH); | |
delay(300); | |
digitalWrite(i, LOW); | |
} | |
digitalWrite(led1Pin, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment