Results 1 to 5 of 5
  1. #1
    10+ Posting Member
    Join Date
    Apr 2014
    Location
    United States
    Posts
    15
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    No match for operator in a switch case

    Code:
    #include 
    
    #include 
    #include 
    #include "utility/Adafruit_PWMServoDriver.h"
    
    Adafruit_MotorShield AFMS = Adafruit_MotorShield();
    
    Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
    
    int CodeIn;
    //int KpinNo; 
    //int Koutpin;
    String asi;
    long asil;
    int val;
    
    //String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
    
    void setup() {
      Serial.begin(115200);
      Serial.println("ASI Stepper test!");
      AFMS.begin();
      myMotor->setSpeed(1000);  // 10 rpm
    }
    
    void loop() {
     
      if (Serial.available()) {
        CodeIn = getChar();
        if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
         }
    
    }
    
    char getChar()// Get a character from the serial buffer
    {
      while(Serial.available() == 0);// wait for data
      return((char)Serial.read());// Thanks Doug
    }
    
    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
      case 'P'://Found the second identifier Turn coordinator
      
      {
       asi = ""; // clears ASI value so you can extract number
       asi +=getChar(); //Gets char and appends to ASI eg 0
       asi +=getChar();// Gets char appends to ASI eg 3 so ASI = 30 this is not a number its a ascii string
       asi +=getChar();// ditto
    
       int asil = asi.toInt(); //converts the string to an integer number ASII is the value you then check
        val = asil;
    
      
    //  if (asi > asil)
        switch(asil)
        case 'asiup':
         if (asil < asi)
        myMotor->step(10, FORWARD, INTERLEAVE);
      
     break;
      
         case 'asidn':
          if (asil > asi);
         myMotor->step(10, BACKWARD, INTERLEAVE);
         
      break;
     
      }
    }
    }
      
      
        
    
    //  (asil=asi);
    Hi, in the above code I keep getting the error "no match for 'operator<' in 'asil < asi' in the first statement and also for the > in the second if statement.

    Could some kind soul look it over and tell me what I've done wrong?

    Thanks Mark
    Last edited by N10669_Mark; 07-14-2014 at 07:56 PM.

  2. #2
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No match for operator in a switch case

    Hi Mark,
    Maybe because asil is an integer and asi is a string ?
    and watch your switch-case (compare int (asil) to string (asidn and asiup)
    Something else, you've declared 2 times asil (long and int)

    ryan

    errr, am I the only one that i can't read full code from the forum (always miss part of code, ex : incomplete while, incomplete include and other missing characters) ?

  3. #3
    75+ Posting Member



    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No match for operator in a switch case

    Ryan, there's an incompatibility between the the Arduino Sketchbook programmer and this forum's editor. The sketchbook programmer imbeds some additional non-printing characters into your code so that the it will work with the Arduino boards. The forum's code input editor chokes when it encounters one of these command characters and stops accepting your input until it gets back in sync. The "include" statement in your sketchs has one of these characters, but it also occurs elsewhere.

    I found a way to get around it by copying the sketch to a regular text editor as an intermediate step and then copy/pasting it into the forum as simple text input. You click on the "Wrap [C*DE] button in this editor to produce the tags and then paste your sketch in between the two tags. It now shows up in the scroll box correctly.

  4. #4
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No match for operator in a switch case

    Good to know
    Thanks for the information, SteveL
    ryan

  5. #5
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No match for operator in a switch case

    mark this is the same code as the other post, have you looked at the reply i sent about that?