Project - LED Code Update
From Physical Programming
OK so this is the code I'm trying to work with to make the Blue LED's have a pattern of change...
Not too sure what is wrong here.
int L3= 3;
int L5= 5;
int L6= 6;
int L9= 9;
int L10 = 10;
int L11 = 11;
int Phase1 = { 5, 9, 11 }
int Phase2 = { 3, 6, 10 }
int Phase3 = { 3, 5 }
int Phase4 = { 5, 6 }
int Phase5 = { 9, 11 }
pinMode (L3, OUTPUT)
pinMode (L5, OUTPUT)
pinMode (L6, OUTPUT}
pinMode (L9, OUTPUT)
pinMode (L10, OUTPUT)
pinMode (L11, OUTPUT}
void setup()
{
}
void loop()
{
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Phase1, value);
delay(1000);
}
for(value = 255; value >=0; value-=5)
{
analogWrite(Phase1, value);
delay(1000);
}
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Phase2, value);
delay(100);
}
for(value = 255; value >=0; value-=5)
{
analogWrite(Phase2, value);
delay(1000);
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Phase3, value);
delay(1000);
}
for(value = 255; value >=0; value-=5)
{
analogWrite(Phase3, value);
delay(1000);
}
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Phase4, value);
delay(1000);
}
for(value = 255; value >=0; value-=5)
{
analogWrite(Phase4, value);
delay(1000);
}
for(value = 0 ; value <= 255; value+=5)
{
analogWrite(Phase5, value);
delay(1000);
}
for(value = 255; value >=0; value-=5)
{
analogWrite(Phase5, value);
delay(1000);
}
To run that with the VU meter I am looking at using while and making a statement that is always true so that it continually runs...
Is this the right way to combine the codes?
while ( ) the above code }
The Updated VU meter code adjusted to my needs...
#define NUMBER_OF_LEDS 6
#define NUMBER_OF_SAMPLES 20
#define VU_METER_DISPLAY_DELAY 10
byte voltageReferencePin = 0;
byte voltagePin = 0;
byte ledPins[NUMBER_OF_LEDS] = { 1 , 2 , 4 , 7 , 8 , 13 };
byte voltageComparisonThresholds[] = { 0 , 1 , 3 , 5 , 8 , 10 };
int voltageReference = 0;
int samples[NUMBER_OF_SAMPLES] = {0};
int sample = 0;
int sampleTotal = 0;
byte sampleIndex = 0;
void setup() {
for (byte i=0; i<NUMBER_OF_LEDS; i++){
pinMode(ledPins[i],OUTPUT);
}
pinMode(voltageReferencePin,INPUT);
pinMode(voltagePin,INPUT);
}
void loop(){
sampleTotal -= samples[sampleIndex];
samples[sampleIndex] = analogRead(voltageReferencePin);
sampleTotal += samples[sampleIndex++];
if (sampleIndex >= NUMBER_OF_SAMPLES) {sampleIndex = 0;}
sample = sampleTotal / NUMBER_OF_SAMPLES;
for (byte i=0; i<NUMBER_OF_LEDS; i++){
if ( analogRead(voltagePin) >= voltageReference + voltageComparisonThresholds[i] ) {
digitalWrite(ledPins[i],LOW);
}else{
digitalWrite(ledPins[i],HIGH);
}
delay(VU_METER_DISPLAY_DELAY);
}
}

