The problem is that int sensorValue = analogRead(sensorPin1); isn't just a declaration, it has an initializer too. The rule is you aren't allowed to jump over initializers (the error message used to be a lot more helpful and said that explicitly I seem to remember).
The reason for this is quite hard to explain, it is easier to understand if instead of an int the variable is an object from a class with several different constructors. If the initializer is skipped over, but then the object is used later on, the object won't have been properly constructed, and the compiler won't have known which constructor to call.
You can get round it by removing the initializer and using ordinary assignment:
case SENDDATA:
{
int sensorValue;
sensorValue = analogRead(sensorPin1);
Wire.send(sensorValue);
.....
Thanks, folks. I think I understand. G++ handles it just fine, but I guess the version used for this processor is a bit more restrictive. It was an easy fix to move the declaration out. To whoever simplified my code by suggesting I could merge the read into the write, this was a synthetic sample, not my real code. I needed to save that value for later use in the program.
Can anyone tell me why this Switch Case give an error on Case 1:
switch (mode)
{
case 0:
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
break;
case 1: //can't resolve 'jump to case label' error
{
int ledLevel = random(0,ledCount); // use Random gen to simulate audio peaks
break;
}
}
switch (mode)
{
case 0:
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
[glow]ledLevel[/glow] = map(sensorReading, 0, 1023, 0, ledCount);
break;
case 1: //can't resolve 'jump to case label' error
{
[glow]int ledLevel[/glow] = random(0,ledCount); // use Random gen to simulate audio peaks
break;
}
}
Local and global variables of the same name is rarely a good idea.
Exactly what error message are you seeing?
Does enclosing the case code in {} as suggested above make any difference?