Both pins are digital pin 3. The right one goes to the EL Wire and the left one can go to whatever you want! |
int wirePin[] = {3,4,5}; // create array values corresponding to wire pinOuts
int switchPin[] = {3,4,5}; // same with switch pins
void setup() {
for(int i = 0;i<3;i++) {
pinMode(wirePin[i], OUTPUT); // Set the wire pins as output
pinMode(switchPin[i], INPUT); // Set the switch pins as input
}
}
void loop() {
//nothing needs to loop!
}
In the project linked above I initially had all that extra code because I was using the Lady Ada tutorial on programming switches with the Arduino and since on an Arduino each pin can only do one thing they used pin 2 for input and pin 12 for output. Their code had to use conditional statements to get the switch to work the LED.Here is another program version using functions to assign different patterns to the 3 switches:
int wirePin[] = {3,4,5}; // create array values corresponding to wire pinOuts
int switchPin[] = {6,7,8}; // same with switch pins
int val[3]; // variable for reading the pin status
void setup() {
for(int i = 0;i<3;i++) {
pinMode(wirePin[i], OUTPUT); // Set the wire pins as output
pinMode(switchPin[i], INPUT); // Set the switch pins as input
val[i] = 0; // Set val array to 0
}
}
void loop(){
for(int i = 0;i<3;i++) {
val[i] = digitalRead(switchPin[i]); // read input values and store it in val array
if (val[0] == HIGH) {
sequence(5);
}
if (val[1] == HIGH) {
flash(5);
}
if (val[2] == HIGH) {
alternate(2);
}
// check if buttons are not pressed
if (val[i] == LOW) {
digitalWrite(wirePin[i], LOW); // turn wires off
}
}
}
void sequence(int times) {
for(int i = 0;i<times;i++) {
digitalWrite(wirePin[0], HIGH);
delay(90);
digitalWrite(wirePin[0], LOW);
digitalWrite(wirePin[1], HIGH);
delay(90);
digitalWrite(wirePin[1], LOW);
digitalWrite(wirePin[2], HIGH);
delay(90);
digitalWrite(wirePin[2], LOW);
}
}
void flash(int times) {
for(int i = 0;i<times;i++) {
for(int j = 0;j<3;j++) {
digitalWrite(wirePin[j], HIGH);
}
delay(100);
for(int j = 0;j<3;j++) {
digitalWrite(wirePin[j], LOW);
}
delay(100);
}
}
void alternate(int times) {
for(int i = 0;i<times;i++) {
digitalWrite(wirePin[0], HIGH);
digitalWrite(wirePin[1], HIGH);
delay(170);
digitalWrite(wirePin[0], LOW);
digitalWrite(wirePin[1], LOW);
digitalWrite(wirePin[2], HIGH);
delay(170);
digitalWrite(wirePin[2], LOW);
digitalWrite(wirePin[2], HIGH);
digitalWrite(wirePin[1], HIGH);
delay(170);
digitalWrite(wirePin[2], LOW);
digitalWrite(wirePin[1], LOW);
digitalWrite(wirePin[0], HIGH);
delay(170);
digitalWrite(wirePin[0], LOW);
digitalWrite(wirePin[0], HIGH);
digitalWrite(wirePin[2], HIGH);
delay(170);
digitalWrite(wirePin[0], LOW);
digitalWrite(wirePin[2], LOW);
digitalWrite(wirePin[1], HIGH);
delay(170);
digitalWrite(wirePin[1], LOW);
}
}
No comments :
Post a Comment