hey can somebody give me some guidance on the syntax for this switch statement, i can see what im doing wrong:
switch (num.substring (num.length() - 1))
{
thanks
hey can somebody give me some guidance on the syntax for this switch statement, i can see what im doing wrong:
switch (num.substring (num.length() - 1))
{
thanks
error - switch quantity not an integer
hey can somebody give me some guidance on the syntax for this switch statement, i can see what im doing wrong:
switch (num.substring (num.length() - 1))
{
error: switch is not an integer
Thanks
sorry, realised this is in the wrong place, have reposted
have you already read this?
http://arduino.cc/en/Reference/SwitchCase
yep, its the dodgy substring request and the way i have stated it that is the problem i think, i have used switch case statements alot but usually add ' ' around a character, just not sure of the procedure if i want the character to be a substring
thanks
substring() returns a String. Swtice statements don't work with the String object.
ahh so i need to extract a particular character from a string rather than a smaller string? I have used a switch case with a character before without issue (ie not an integer)
ianmgreen:
ahh so i need to extract a particular character from a string rather than a smaller string? I have used a switch case with a character before without issue (ie not an integer)
Yes, you need a char instead of a String. Also, to avoid confusion, you're talking about a String, not a string. In the Arduino environment, they are two different animals.
ok so working from that angle i would try this
switch (num.charAt(num.length() - 1))
{
but still no joy
ianmgreen:
but still no joy
Feel free to elaborate.
It's also a good idea to provide all of your code, or at least enough (setup and loop functions and any applicable declarations) that allows us to compile the code and replicate the error.
In this case the error message is very descriptive.
substring() returns a String object. Switch require integers. So you can't use substring() with Switch.
Threads merged.
num.charAt compiles fine for me.
void setup() {
String num = "Don't use generic variable names like num";
switch (num.charAt(num.length()-1)) {
case 'm':
// do something
break;
}
}
void loop() {
}
still wont compile for me , including the entire code to see if this helps anybody spot where im going wrong
int key;
int store;
int trigger;
int statuscheck;
int pollcheck;
int pollcount;
int hangcheck;
String num = "";
String numcheck = "";
String dial = "";
String dialprint = "";
String report;
String okcheck;
char digit[]= "D1234567890*#ABCX";
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
pinMode(9, INPUT); //trigger (EST PIN)
pinMode(2, OUTPUT); //binary 1
pinMode(3, OUTPUT); //binary 2
pinMode(4, OUTPUT); //binary 3
pinMode(5, OUTPUT); //binary 4
pinMode(6, OUTPUT); //Register select
pinMode(7, OUTPUT); //Chip select
pinMode(8, OUTPUT); //Read-write register
pinMode(11, OUTPUT); //Theta clock
digitalWrite(7,HIGH); // chip select -reset on
delay(1000);
digitalWrite(7,LOW); // chip select - reset off
delay(100);
digitalWrite(6,HIGH); //Register select
digitalWrite(8,LOW); //Read-write register
digitalWrite(2, HIGH); //b0
digitalWrite(3, LOW); //b1
digitalWrite(4, LOW); //b2
digitalWrite(5, HIGH); //b3
delay(10);
digitalWrite(11,HIGH); //clock on
delay(10);
digitalWrite(11,LOW); //clock off
delay(10);
digitalWrite(6,HIGH); //Register select
digitalWrite(8,LOW); //Read-write register
digitalWrite(2, HIGH); //b0
digitalWrite(3, LOW); //b1
digitalWrite(4, LOW); //b2
digitalWrite(5, LOW); //b3
delay(10);
digitalWrite(11,HIGH); //clock on
delay(10);
digitalWrite(11,LOW); //clock off
delay(10);
digitalWrite(6,LOW); // register select -
digitalWrite(8,HIGH); // read-write register -
delay(10);
digitalWrite(2, LOW); //b0
digitalWrite(3, LOW); //b1
digitalWrite(4, LOW); //b2
digitalWrite(5, LOW); //b3
digitalWrite(11,HIGH); //clock on
delay(10);
digitalWrite(11,LOW); //clock off
delay(10);
store = 16;
pollcheck = 0;
pollcount = 0;
statuscheck = 0;
hangcheck = 0;
}
void loop()
{
pinMode(2, INPUT); //binary 1
pinMode(3, INPUT); //binary 2
pinMode(4, INPUT); //binary 3
pinMode(5, INPUT); //binary 4
if (pollcheck == 0 ) //
do //
{ Serial3.println("poll 0088-047"); //
// Serial.println("polling"); // debug statement //
delay(100); //
if (Serial3.available()) //
{ // pollcheck
//Serial.println("polled"); // debug statement //
pollcheck = 1; //
} //
} //
while (pollcheck == 0); //
if (pollcheck == 1) //
{pollcount ++; } //
if (digitalRead(9) == HIGH)
{
while(key < 13 && key != 0 && hangcheck != 1)
{
//(bit1)
if (digitalRead(2) == HIGH)
{
key = 1;
}
else
{
key = 0;
}
//(bit2)
if (digitalRead(3) == HIGH)
{
key = key + 2;
}
// (bit4)
if (digitalRead(4) == HIGH)
{
key = key + 4;
}
//(bit8)
if (digitalRead(5) == HIGH)
{
key = key + 8;
}
//Serial.println(key); // debug line
if (key != store || (key == store && (digitalRead(9) == HIGH) && (trigger != 1)))
{
num = num + (digit[key]);// add number from array corresponding to keyvalue
}
store = key;
if (digitalRead(9) == HIGH)
{
trigger = 1;
}
}
if (key = 0)
{
hangcheck = 1;
}
}
switch (num.charAt(num.length()-1))
{
case: 'A'
dialprint = num;
num = "";
dialprint.replace('A',' ');
dialprint.replace('B',' ');
dialprint.replace('C',' ');
dialprint.replace('D',' ');
dialprint.trim();
Serial.println("set isdn codec a");
Serial3.println("set isdn 3k7 stereo");
delay(100);
Serial.println("set rem add 1 " + dialprint);
Serial3.println("set rem add 1 " + dialprint);
delay(100);
Serial.println("dial");
Serial3.println("dial");
break;
case: 'B'
dialprint = num;
num = "";
dialprint.replace('A',' ');
dialprint.replace('B',' ');
dialprint.replace('C',' ');
dialprint.replace('D',' ');
dialprint.trim();
Serial.println("set isdn codec B");
Serial3.println("set isdn APTX:3K7Stereo64Kbps");
delay(100);
Serial.println("set rem add 1 " + dialprint);
Serial3.println("set rem add 1 " + dialprint);
delay(100);
Serial.println("dial");
Serial3.println("dial");
break;
case: 'C'
dialprint = num;
num = "";
dialprint.replace('A',' ');
dialprint.replace('B',' ');
dialprint.replace('C',' ');
dialprint.replace('D',' ');
s
dialprint.trim();
Serial.println("set isdn codec C");
Serial3.println("set isdn APTX:7K5Mono64Kbps");
delay(100);
Serial.println("set rem add 1 " + dialprint);
Serial3.println("set rem add 1 " + dialprint);
delay(100);
Serial.println("dial");
Serial3.println("dial");
break;
case: 'D'
num = "";
Serial.println("hang");
Serial3.println("hang");
break;
}
if (pollcount >= 200)
{
pollcheck = 0;
pollcount = 0;
}
I'd say you're missing at least one closing } off the end, but I'm posting from a phone, so can't compile.
case: 'A'
Wrong.
Read the switch/case reference page again.
Adding the } at the end, fixing the case statements, and removing the line that has just the s on it, I get this error:
Binary sketch size: 8708 bytes (of a 258048 byte maximum)