Go Down

Topic: Need a little help with my music vu meter (Read 577 times) previous topic - next topic

Confused8737

//Music led
int value = 0;                            // variable to keep the actual value
int ledPin[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13};                           // light connected to digital pin 9
int val;
int n=0;
int time;
int NewVal;
int NewTime;
#define sensorRight 0
#define sensorLeft 1
int sensor

void setup()
{
 int oldMusicLeft=512;
 int oldMusicRight=512;
 for(int k=0;k<=13;k+=1)
 {
   pinMode(ledPin[k], OUTPUT);
 }
}

int checkVal(sensor)
{
 val=analogRead(sensor);
 if((450<=val)&&(val<=550))
 {
   NewVal=0;
   return NewVal;
 }
 if(val<=620)
 {
   NewVal=map(val,50,620,0,7);
   return NewVal;
 }
 if(val>=516)
 {
   NewVal=map(val,620,1050,0,7);
   return NewVal;
 }
}

//int greaterValue(oldMusic, newMusic)
//{
//  if(newMusic<=oldMusic)          //if the old value is greater
//  {
//    for(n=oldMusic;n>=newMusic;n-=1)    //turn lights to newMusic
//    {
//      digitalWrite(n,LOW);
//      delay(30);
//    }
//    return yes=1;
//  }
//  return yes=0;
//}

void zero(int oldMusic, int newMusic)
{
 int count;
 if(count==10)
 {
   oldMusic=550;
   newMusic=550;
   return;
 }  
 if((oldMusic<=(newMusic + 5))&&(oldMusic>=(newMusic-5)))
 {
   count=count+1;
   return;
 }
 else
 {
   count=0;
   return;
 }
}
 

void loop()
{
 int newMusicLeft;
 int newMusicRight;
 int oldMusicLeft=520;
 int oldMusicRight=520;
 for(;;)
 {
 newMusicLeft=checkVal(sensorLeft);
 newMusicRight=checkVal(sensorRight);
 zero(oldMusicLeft, newMusicLeft);
 zero(oldMusicRight, newMusicRight);
 if(newMusicLeft<=oldMusicLeft)          //if the old value is greater
 {
   for(n=oldMusicLeft;n>=newMusicLeft;n-=1)    //turn lights to newMusic
   {
     digitalWrite(n,LOW);
   }
 }
 if(newMusicRight<=oldMusicRight)          //if the old value is greater
 {
   for(n=oldMusicRight;n>=newMusicRight;n-=1)    //turn lights to newMusic
   {
     digitalWrite(n,LOW);
   }
 }
 if(newMusicLeft>=oldMusicLeft)                //if the level is higher
 {
   for(int n=oldMusicLeft;n<=newMusicLeft;n+=1)
   {
     digitalWrite(n,HIGH);
     delay(30);
   }
 }
 if(newMusicRight>=oldMusicRight)                //if the level is higher
 {
   for(n=oldMusicRight;n<=newMusicRight;n+=1)
   {
     digitalWrite(n,HIGH);
   }
 }
 delay(30);
 oldMusicLeft=newMusicLeft;
 oldMusicRight=newMusicRight;
 delay(10);
 }
}

This is my code and every time that I try and compile it I get the error message:

error: expected initializer before 'void'

I have no idea why this is giving me this error message.  Any input would be wonderful.  Thanks

Coding Badly

Semi-colon is missing...

Code: [Select]
int sensor

Type is missing...

Code: [Select]
int checkVal(sensor)

Please use the hash (button with # on the face) when including code in a message.

Good luck,
Brian

Go Up