I am trying to set up a LilyPad on a dress as follows:
Two switches, which allow a possible of 4 combinations, to control the current state/function of LED's.
17 LED's (one is soldered to board on pin 13) that will fade according to a modified fade code to make it look like a heartbeat.
I want to be able to have something like this:Arduino Playground - AnalogAndDigitalFireflies
with pins 2-19, excepting pin 13, which will only ever make a simple heartbeat type of pulse.
I don't understand how the above project's code works, but it seems that he managed to make a random PWM fade out of both the PWM and Digital pins.
I am trying to make the dress light up and fade on/off pins 2-19 (excepting 13) at random intervals, but I can't find anything about how to do this.
I have tried extensive reading about the Fade, and PWM functions, and being new to this I can't really understand the code mentioned above.
So far I have this:
/* JOJO'S DRESS CODE
* This code is designed to connect the Arduino 328 (Lilypad clone)
* which contains 17 LED's (one red pin 13, and 16 on dress)
* Using 2 switches, a possibile 4 options can be built into this code.
*
* Mine are as follows:
* [-----------]
* [ 0 | 0 ]Option 1: No Lights
* [ 0 | 1 ]Option 2: HeartPulse only
* [ 1 | 0 ]Option 3: Starlight Fading random time, max 7 @ once
* [ 1 | 1 ]Option 4: Flash random pin, random (200,1000) max 7 @ once
* [-----------]
*/
int maxon = 5; //Max
void setup() {
// put your setup code here, to run once:
pinMode(0,INPUT);
pinMode(1,INPUT);
digitalWrite(1,LOW);//pulldown important to not steal precious power!
digitalWrite(0,LOW);//enables internal pulldown resistor
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(16,OUTPUT);
pinMode(17,OUTPUT);
pinMode(18,OUTPUT);
pinMode(19,OUTPUT);
}
void loop(){
//VARIABLES
const byte LEDArray[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19};
int pinCount =17;
int switchA = A0;
int switchB = A1;
///FIRST CASE, SWITCH 00, OPTION 1----------------------
if(digitalRead(switchA) == LOW){ //if first switch off
if(digitalRead(switchB) == LOW){ //and second switch off also
for(int thisPin = 0; thisPin < pinCount; thisPin++){ //cycle through all pins on array
digitalWrite(LEDArray[thisPin],LOW);} //and turn them off
digitalWrite(13,LOW); //also, turn off pin 13 (red LED)
}
}
//SECOND CASE, SWITCH 01, OPTION 2---------------------
if(digitalRead(switchA) ==LOW){ //if first switch off
if(digitalRead(switchB) ==HIGH){ // and second switch on
for (int thisPin = 0; thisPin < pinCount; thisPin++) { //cycle through all pins on array
digitalWrite(LEDArray[thisPin],LOW);} //and turn them off
int brightness =0; //create a variable, named brightness
analogWrite(13,brightness); // give value to pin13, redLED
if(brightness == 0 || brightness < 255){ //if 'brightness' is 0-254
analogWrite(13,brightness); // value is shown via LED
brightness = brightness +1; //add 1 to value
delay(10); //delay to allow you to see "fade"
}
else if(brightness <=255 && brightness > 0){ //when it does not agree with above statement (is 255)
brightness = brightness -3; //go down by 3's
analogWrite(13,brightness); //apply brightness
delay(5); //wait half time of above. Will return to first statement when false
}
}
}
//THIRD CASE, SWITCH 10, OPTION 3-------------------------
if(digitalRead(switchA) ==HIGH){
if(digitalRead(switchB) ==LOW){
digitalWrite(13,LOW); //write this pin low, not needed
int timeOff = random(1000,5000); //random time off parameters
int timeOn = random(600,3001); //random time on parameters
digitalWrite(LEDArray[random(0,18)],HIGH); //write a random LEDArray pin as high***NEED PWM?!***
delay(timeOn); //NEED TO MAKE RANDOM FADE TIME, NOT TIME HIGH
}
}
}
If anyone can help me put this in order, or point me in the right direction, I would really appriceate it. I would even settle for the LED's just following option 4, and flashing on and off for a random set of time, but I don't quite know how to do this AND set a limit as to how many come on at once.
If possible, I would like to make sure that 7 are on at any given time.
Thank you for your time. Andy