function not decleared, why not

#include <Arduino.h>
#include <Streaming.h>  /* http://arduiniana.org/libraries/streaming/ */

#define   KEY_ESC         0x1B
#define   KEY_MOVE        0x5B
#define   KEY_NORHT       0x41
#define   KEY_SOUHT       0x42
#define   KEY_EAST        0x43
#define   KEY_WEST        0x44

boolean   recvCommand  =  false;

void setup() {
  Serial.begin(9600);
  Serial.println("Enter Command: ");
  Serial << "BIN\tOCT\tDEC\tHEX" << endl;
}

void loop() {
  char c = Serial.read(); // note read() returns an int, char c = converts it to a char
  if (c != -1) {  // read() return -1 if there is nothing to be read.
    // got a char show it
    Serial.print (c, BIN);
    Serial.print("\t");
    Serial.print(c, OCT);
    Serial.print("\t");
    Serial.print(c, DEC);
    Serial.print("\t");
    Serial.print(c, HEX);
    Serial.print("\t");
    Serial.println(c);
    recvCommand = true;
  }
  if (recvCommand == true && c == KEY_ESC) {
    Serial.println(" Got Escape key");
    recvCommand = false;
  } else  if (recvCommand == true && c == KEY_MOVE) {
    Serial.println(" Got move key");
    char m = Serial.read(); // note read() returns an int, char c = converts it to a char
    switch (m) {
      case 'KEY_NORHT':
        printMove("Norht");
        break;
      case 'KEY_SOUHT':
        printMove("SOUHT");
        break;
      case 'KEY_EAST':
        printMove("EAST");
        break;
      case 'KEY_WEST':
        printMove("WEST");
        break;

        recvCommand = false;
    }
  } else if (    recvCommand == true) {
    Serial.println("Decode other key");
    recvCommand = false;
  }

  void  printMove(char str1) {
    Serial.print("Move dish ");
    Serial.println(str1);
    recvCommand = false;
  }
}

This code wont compil;e while the printMove function is not decleared.
The question is why not, what did i missed.

Harry

Because you used the Arduino IDE's Auto Format on your code, the indentation provides a nice visual representation of the program structure. If you carefully study the indentation of the printMove() function, I think you'll see the problem. This is a very useful troubleshooting technique.

After 313 posts, don't you think it is time you posted the actual error messages the IDE returns?

To expand on what @pert hinted, if, after auto-format, a function definition doesn't start on the extreme left, you've done something wrong.
In this case you've tried to define a function inside another function.
C++ doesn't allow that.

Code should be in a function but a function should not be in function.

Thanx, that problem is solved now.
But now thw switch function part is never reached.
P.S. I am visual handicapt, some websites and the arduino IDE are not perfect. Sorry fo my handicap

We can't see your code either.

Or your debug output.

Don’t put the case parameters in ‘quotes’... why did you do that ?

Here it is with some minor problems corrected:

const byte KEY_ESC         =0x1B;
const byte KEY_MOVE        =0x5B;
const byte KEY_NORHT       =0x41; // A
const byte KEY_SOUHT       =0x42; // B
const byte KEY_EAST        =0x43; // C
const byte KEY_WEST        =0x44; // D


boolean   recvCommand  =  false;


void setup()
{
  Serial.begin(9600);
  delay(200); // Give Serial Monitor time to connect, which causes a reset.
  Serial.println("Enter Command: ");
  Serial.println("BIN\tOCT\tDEC\tHEX");
}


void loop()
{
  int c = Serial.read(); // note read() returns an int, char c = converts it to a char
  if (c != -1)    // .read() return -1 if there is nothing to be read.
  {
    // got a char show it
    Serial.print (c, BIN);
    Serial.print("\t");
    Serial.print(c, OCT);
    Serial.print("\t");
    Serial.print(c, DEC);
    Serial.print("\t");
    Serial.print(c, HEX);
    Serial.print("\t");
    Serial.println((char)c);
    recvCommand = true;
  }


  if (recvCommand == true && c == KEY_ESC)
  {
    Serial.println(" Got Escape key");
    recvCommand = false;
  }
  else  if (recvCommand == true && c == KEY_MOVE)
  {
    Serial.println(" Got move key");
    delay(10); // Give a little time for character to be received
    int m = Serial.read(); // note read() returns an int, char c = converts it to a char
    switch (m)
    {
      case KEY_NORHT:
        printMove("Norht");
        break;
      case KEY_SOUHT:
        printMove("SOUHT");
        break;
      case KEY_EAST:
        printMove("EAST");
        break;
      case KEY_WEST:
        printMove("WEST");
        break;
    }
    recvCommand = false;
  }
  else if (recvCommand == true)
  {
    Serial.println("Decode other key");
    recvCommand = false;
  }
}


void  printMove(const char *str1)
{
  Serial.print("Move dish ");
  Serial.println(str1);
  recvCommand = false;
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.