i have a problem with my case and i get compilation errors.
here is the code
/*
microphone sketch
SparkFun breakout board for Electret Microphone is connected to analog pin 0
*/
int i=0;
unsigned long currentTime = 0; //this variable will be overwritten by millis() each iteration of loop
unsigned long pastTime = 0; //no time has passed yet
unsigned long current = 0; //this variable will be overwritten by millis() each iteration of loop
unsigned long past = 0;
char letter[4];
char temp[4];
int currentState = 0; //the default state
int wait = 100; //no need to wait, nothing has happened yet
int flag =0;
const int ledPin = 13; //the code will flash the LED in pin 13
const int middleValue = 512; //the middle of the range of analog values
const int numberOfSamples = 16; //how many readings will be taken each time
int sample; //the value read from microphone each time
long signal; //the reading once you have removed DC offset
long averageReading; //the average of that loop of readings
long runningAverage=0; //the running average of calculated values
const int averagedOver= 4; //how quickly new values affect running average
//bigger numbers mean slower
const int threshold=32000; //at what level the light turns on
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
long sumOfSquares = 0;
for (int i=0; i<numberOfSamples; i++) { //take many readings and average them
sample = analogRead(0); //take a reading
signal = (sample - middleValue); //work out its offset from the center
signal *= signal; //square it to make all values positive
sumOfSquares += signal; //add to the total
}
averageReading = sumOfSquares/numberOfSamples; //calculate running average
runningAverage=(((averagedOver-1)*runningAverage)+averageReading)/averagedOver;
if (runningAverage>threshold){ //is average more than the threshold ?
digitalWrite(ledPin, HIGH); //if it is turn on the LED
past = current; //currentTime at this point is the current time from the previous iteration, this should now be pastTime
current = millis();
unsigned long timePassed2 = current - past;
if(timePassed2 > 200){
switch(letter){
case '.':
temp = 'E';
return;
case '-':
temp = 'T';
return;
case '.-':
temp ='A';
return;
case '---':
temp ='O';
return;
case '..':
temp ='I';
return;
case '-.':
temp='N';
return;
case '...':
temp = 'S';
return;
case '....':
temp = 'H'
return;
case '.-.':
temp = 'R';
return;
case '-..':
temp='D';
return;
case '.-..':
temp='L';
return;
case '-.-.':
temp ='C';
return;
case '..-':
temp = 'U';
return;
case '--':
temp = 'M';
return;
case '.--':
temp = 'W';
return;
case '..-.':
temp = 'F';
return;
case '--.':
temp ='G';
return;
case '-.--':
temp = 'Y';
return;
case '.--.':
temp = 'P';
return;
case '-...':
temp = 'B';
return;
case '...-':
temp = 'V';
return;
case '-.-':
temp = 'K';
return;
case '.---':
temp = 'J';
return;
case '-..-':
temp = 'X';
return;
case '--.-':
temp = 'Q'
return;
case '--..':
temp = 'Z';
return;
case ' ':
delay(wgap);
return;
}
Serial.print(temp);
i=0;
}
}
else{
digitalWrite(ledPin, LOW); //if it isn't turn the LED off
pastTime = currentTime; //currentTime at this point is the current time from the previous iteration, this should now be pastTime
currentTime = millis(); //currentTime is now the current time (again).
unsigned long timePassed = currentTime - pastTime; //this is roll-over proof, if currentTime is small, and pastTime large, the result rolls over to a small positive value, the time that has passed
if(timePassed > 30 && timePassed <200) //part1 of the state engine
{
if(timePassed >= wait) //part1 of the state engine
{
letter[i] = '-';
i++;
}
else {
letter[i] = '.';
i++;
}
}
}
}
it receives audio from analog0 and it counts the millis between the the values over the threshold to determin whether it is a dot or a dash.
it worked fine and i had to my serial seperated groups of - and . ! the next step is where the swich comes to check whether the value that i have is equal to on of this and print to my serial the apropriate letter.
case label does not reduse to an integer constant
this the compilation error that i get.
any ideas here ?