Control Problems with Scratch


#1

If I create a really simple program in scratch, it works fine:

But if I try and add control statements, they just don’t work. Here are some examples, none of which work.

In this example, the motor starts, but does not stop when I wave my hand in front of the sensor:

In the following two examples, nothing happens when I press the A button:

What am I doing wrong?

Thanks


#2

Regarding the ultrasonic sensor @mikebian, I’m not sure you’re doing anything wrong. I stumbled upon an unexpected workaround, and posted a response here a couple months ago. (No response from Makeblock folks why this works or why it seems to be needed).

Something you might try.


#3

@mikebian

I’m not familiar with the sensor problem mentioned by @larry. Looking at your code though, I noticed that there is no looping, which means that the code executes once, and never checks the sensor again. When you click the mBot Program icon, it will pull up the code that will be sent to the mBot.


The void setup() function is the only place that the code will execute and that is where the sensor is checked.

In the example below, I added a loop and changed the IF to a IF-ELSE


Now most of the code is in the void loop() function, which will loop “forever”. This means that the ultrasonic sensor will be tested many times. The IF checks the logical state of the test (true or false). If true, stop the motor, else (false) start the motor.

Hope this helps.

Mike


#4

Yea, good catch Mike. Thinking about that earlier problem I had I just overlooked the obvious missing loop. That said, the earlier problem I mentioned was due to the MeIR.h file not being #include(d) automatically by just trying to poll the IR sensor.

Larry


#5

This does not work for me. It actually does nothing.

I’d really like to get the IR receiver working from Scratch and I can’t do that. I can reload the original program and then the IR receiver works fine. Using your ultrasonic sensor example, I modified my IR program as follows:

But this still does not work. If you look at the default program, there are things there that would seem to be needed, but are not generated with Scratch:

MeInfraredReceiver infraredReceiverDecode(PORT_6);

void IrProcess()
{
infraredReceiverDecode.loop();
irRead = infraredReceiverDecode.getCode();
switch(irRead)
.
.
.

How do I get the IR controller to work in Scratch?

Thanks


#6

Ok, this is strange. I have the same blocks as you, but the code is different. The motor on my mBot runs only while I’m holding the ‘A’ button on the IR remote.

I’m using mBlock v3.1 on a Windows machine (I don’t have any iDevices). Make sure you have the most up-to-date mBlock v3.1 software. If that doesn’t help, you might want to check with tech support.


#7

Thanks, I did have an older version of the mBot software. I updated it and now it generates the exact same code that you displayed. However, it still does not work. I’ll try the tech support email address.


#8

The issue was that I had the wrong board selected. I have the starter kit with the ME Orion board and I previously had the mBot board selected. When I selected the correct board, I got a different set of building blocks, but they now work. Not sure why there is different set for each of these as the functionality should be the same, but it mostly works now. The ME Orion blocks are not as user friendly as the mBot ones are. For instance, you have to put in the hex codes from the infrared header file rather then just specifying the A button.

Thank you to those that tried to help.


#9

I am in the same boat. With Scratch v2.0.23, I can connect robot via usb and run/debug code, but I cannot upload the code to the robot. For example, if modified the ultrasonic_car example by replacing the keyboard instructions with the IR instructions. The modified code also displays my IR variable an sensor variables in the window with the sprite of the tank bot. I can run the code and the physical robot will perform just like the sprite. However when I try to upload the code, no errors are reported and the robot does not run.

Mblock 3.1 has the opposite problem. I take the same code and upload it to the robot from Mblock and then disconnect the USB. The robot runs the code while disconnected. However, while I am connected to Mblock with USB, Mblock will not display the variable values and move the sprite like I can in Scratch.

How do I get the correct combined behavior?


#10