Created
December 6, 2013 06:16
-
-
Save e-Gizmo/7819353 to your computer and use it in GitHub Desktop.
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
/* eGizmo LED Shield 2v0 | |
The LED shield functions as a control for LED or light emitting diodes | |
fabricated directly on an Arduino shield. The analog switches can | |
be assigned a function depending on the desired function. | |
Codes by: | |
eGizmo Mechatronix Central | |
April 2, 2013 | |
*/ | |
const int buttonPin = A5; | |
const int buttonPin2 = A4; | |
const int buttonPin3 = A3; | |
// Analog pins A5, A4, and A3 are set as button switches. | |
// Initializes the microcontroller and initially set the digital pins for output as default. | |
void setup() | |
{ | |
pinMode(buttonPin, INPUT_PULLUP); | |
pinMode(buttonPin2, INPUT_PULLUP); | |
pinMode(buttonPin3, INPUT_PULLUP); | |
pinMode(0,OUTPUT); | |
pinMode(1,OUTPUT); | |
} | |
// The following codes include the functions for switches 1, 2 and 3. | |
void loop() | |
{ | |
int buttonState = digitalRead(buttonPin); // Digital read out for A5 | |
int buttonState2 = digitalRead(buttonPin2); // Digital read out for A4 | |
int buttonState3 = digitalRead(buttonPin3); // Digital read out for A3 | |
// FUNCTIONS FOR SWITCH 1 | |
// This set of codes light up the LEDs in increasing order. | |
if(buttonState == 0) | |
{ | |
int i =0; | |
for(i=0; i<=16; i++) | |
{ | |
digitalWrite(i,HIGH); // On | |
delay(10); | |
} | |
for(i=0; i<=16; i++) | |
{ | |
digitalWrite(i,LOW); // Off | |
delay(10); | |
} | |
} | |
// FUNCTIONS FOR SWITCH 2 | |
// This set of codes light up the LEDs altogether | |
else if(buttonState2 == 0) | |
{ | |
int i =0; | |
for(i=0; i<=16; i++) // Even increment | |
{ | |
digitalWrite(i,HIGH); | |
} | |
} | |
// FUNCTIONS FOR SWITCH 3 | |
// This set of codes switches on and off the LEDs in increasing order. | |
else if(buttonState3 == 0) | |
{ | |
int i = 0; | |
for(i=0; i<=16; i++) | |
{ | |
digitalWrite(i,HIGH); | |
delay(100); | |
digitalWrite(i,LOW); | |
delay(100); | |
// On and off for 100ms | |
} | |
} | |
// Turns off all the LEDs if no button is pressed. | |
else | |
{ | |
int i = 0; | |
for(i=0; i<=16; i++) | |
{ | |
digitalWrite(i,LOW); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment