Programming issue


#1

Hello,

I tried writing a basic program to remotely controlling the mBot. Yet after I upladed the code, mBot would not recognize the remote. I used mBlock but here is the Adruino code (note: I’ve removed the brackets on the includes for this post. The code does include the backets): What is the problem?

#include Arduino.h
#include Wire.h
#include Servo.h
#include SoftwareSerial.h

#include MeMCore.h

double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
MeIR ir;
MeDCMotor motor_9(9);
MeDCMotor motor_10(10);
MBotDCMotor motor(0);

void setup(){
ir.begin();
pinMode(A7,INPUT);

}

void loop(){

if(ir.keyPressed(64)){
    motor_9.run((9)==M1?-(0):(0));
    motor_10.run((10)==M1?-(0):(0));
    delay(1000*0.2);
    motor.move(1,30);
}else{
    if(ir.keyPressed(25)){
        motor_9.run((9)==M1?-(0):(0));
        motor_10.run((10)==M1?-(0):(0));
        delay(1000*0.2);
        motor.move(2,30);
    }else{
        if(ir.keyPressed(7)){
            motor_9.run((9)==M1?-(0):(0));
            motor_10.run((10)==M1?-(0):(0));
            delay(1000*0.2);
            motor.move(3,30);
        }else{
            if(ir.keyPressed(9)){
                motor_9.run((9)==M1?-(0):(0));
                motor_10.run((10)==M1?-(0):(0));
                delay(1000*0.2);
                motor.move(4,30);
            }else{
                if(ir.keyPressed(69)){
                    motor_9.run((9)==M1?-(0):(0));
                    motor_10.run((10)==M1?-(0):(0));
                }
            }
        }
    }
}
delay(1000*0.2);
if((0^(analogRead(A7)>10?0:1))){
    motor_9.run((9)==M1?-(0):(0));
    motor_10.run((10)==M1?-(0):(0));
}
ir.loop();

}


#2

@Chessdad,

The first thing I see is that there are no values setting the motor speeds. I think I managed to replicate your blocks, not sure about the bottom section though. Try this example, mBot_IR_Motor_Control.sb2 (74.6 KB).


#3

Hello,

Thanks for your reply mddickey. I thought I had speed but evidently I do not. I think I got ahead of myself. I didn’t want to go from moving in a direction and then immediately change directions. Could be hard on the motor so I put set the motors to 0. I guess I forgot to add the speed after that. I’ll look into it and look at the example you provided.

Many thanks.


#4

I noticed you didn’t have the makeblock libraries loaded in your program:

#include MeMCore.h
or
#include MeOrion.h (tank)
or
"#include Makeblock.h


#5