First time using the Switch / case and I get the following error message:
exit status 1
jump to case label [-fpermissive]
Here is the code/
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue ; // variable to store the value coming from the sensor
int outputHz ; // desired output in hzs
int outHz = 2; //select the pin for output to stepper
int enablePin = 3; //select pin to enable the stepper motor controller
int dirPinOut = 4; //select pin to output dir control to stepper motor controller
int dirPinIn = 5; //select pint to read dir switch high = clockwise
int brakePinIn = 6; // locks motor when high
int cutoff = 50; // above this point enable drive
int RUNled = 13; // turns on when drive is enable or in brake mode
int function; // call subroutine called by switch case statement
float calValue ; // cal value for delay of output
float senone ;
String dir;
String enable;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(enablePin, OUTPUT);
pinMode(RUNled, OUTPUT);
pinMode(outHz, OUTPUT);
pinMode(dirPinOut, OUTPUT);
pinMode(dirPinIn, INPUT);
pinMode( brakePinIn, INPUT);
Serial.begin(250000);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
outputHz = map(sensorValue, 40, 1023, 40, 24000);
if (digitalRead(brakePinIn == HIGH))
{
function = 1;
}
if (outputHz < cutoff)
{
function = 2;
}
if (outputHz >= cutoff && digitalRead(dirPinIn == HIGH))
{
function = 3;
}
if (outputHz >= cutoff && digitalRead(dirPinIn == LOW))
{
function = 4;
}
switch (function)
{
case 1:
digitalWrite(enablePin, LOW);
digitalWrite(RUNled, HIGH);
noTone(outHz);
Serial.print(" case 1");
delay(200);
break;
case 2:
outHz = 31;
digitalWrite(enablePin, HIGH);
digitalWrite(RUNled, LOW);
char enable[] = "OFF";
noTone(outHz);
Serial.print(" case 2");
delay(200);
break;
case 3:
digitalWrite(enablePin, LOW);
digitalWrite(RUNled, HIGH);
digitalWrite(dirPinOut, HIGH);
Serial.print(" case 3");
tone(outHz, outputHz);
break;
case 4:
digitalWrite(enablePin, LOW);
digitalWrite(RUNled, HIGH);
digitalWrite(dirPinOut, LOW);
Serial.print(" case 4");
tone(outHz, outputHz);
break;
}
if (digitalRead(dirPinIn) == HIGH && digitalRead(enablePin) == HIGH)
{
digitalWrite(dirPinOut, HIGH);
dir = "CW";
}
if (digitalRead(dirPinIn) == LOW && digitalRead(enablePin) == HIGH)
{
digitalWrite(dirPinOut, LOW);
dir = "CCW";
}
Serial.println(millis());
Serial.print(outputHz);
Serial.print(" ");
Serial.print(sensorValue);
Serial.print(" ");
Serial.print(dir);
Serial.print(" ");
Serial.print(enable);
}
the line " case 4 is highlighted.
UNO CPU
any help??
Thanks
JB
JB