Code Help #2


  • Global Moderator

    Re: Coding Help

    #include<SmartInventor.h>//include smart inventor library
    void setup() {
      // put your setup code here, to run once:
    SmartInventor.DCMotorUse();//set up motors
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    int leftSensor=analogRead(19);//set left sensor to the left sensor value
    int centerSensor=analogRead(20);//set center sensor to center sensor value
    int rightSensor=analogRead(21);//set right sensor to right sensor value
    if(leftSensor<500){//check if close to something on left
      SmartInventor.DCMotor(M1.CCW,50);SmartInventor.DCMotor(M1,CCW,50);//turn right 
    }
    else if(rightSensor<500){//check if close to something on right 
      SmartInventor.DCMotor(M1.CW,50);SmartInventor.DCMotor(M1,CW,50);//turn left 
    }
    else if(centerSensor<500){//check if close to something in front
      SmartInventor.DCMotor(M1.CW,50);SmartInventor.DCMotor(M1,CW,50);//turn left 
    }
    else{
      SmartInventor.DCMotor(M1,CCW,50);SmartInventor.DCMotor(M2,CW,50);//go foward
    }
    }
    
    This returns the following error:
    Arduino: 1.8.1 (Mac OS X), Board: "Rokit-SmartInventor-mega32_v2"
    
    In file included from /Users/_____/Downloads/program_the_mouse_bot1/program_the_mouse_bot1.ino:1:0:
    /Users/_____/Downloads/program_the_mouse_bot1/program_the_mouse_bot1.ino: In function 'void loop()':
    /Users/_____/Downloads/rokitarduinov1-14/libraries/SmartInventor/SmartInventor.h:116:14: error: expected unqualified-id before numeric constant
     #define CCW  2
                  ^
    /Users/_____/Downloads/program_the_mouse_bot1/program_the_mouse_bot1.ino:13:28: note: in expansion of macro 'CCW'
       SmartInventor.DCMotor(M1.CCW,50);SmartInventor.DCMotor(M1,CCW,50);//turn right 
                                ^
    /Users/_____/Downloads/rokitarduinov1-14/libraries/SmartInventor/SmartInventor.h:115:13: error: expected unqualified-id before numeric constant
     #define CW  1
                 ^
    /Users/_____/Downloads/program_the_mouse_bot1/program_the_mouse_bot1.ino:16:28: note: in expansion of macro 'CW'
       SmartInventor.DCMotor(M1.CW,50);SmartInventor.DCMotor(M1,CW,50);//turn left 
                                ^
    /Users/_____/Downloads/rokitarduinov1-14/libraries/SmartInventor/SmartInventor.h:115:13: error: expected unqualified-id before numeric constant
     #define CW  1
                 ^
    /Users/_____/Downloads/program_the_mouse_bot1/program_the_mouse_bot1.ino:19:28: note: in expansion of macro 'CW'
       SmartInventor.DCMotor(M1.CW,50);SmartInventor.DCMotor(M1,CW,50);//turn left 
                                ^
    exit status 1
    Error compiling for board Rokit-SmartInventor-mega32_v2.
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

  • Global Moderator

    @efraim-fleisher Please note that in the above code the syntax needs "," a comma and NOT a "." period


Log in to reply
 

Looks like your connection to Robolink community was lost, please wait while we try to reconnect.