Toto-Africa on the mbot


#1

toto-africa-mbot.zip (62.7 KB)

I see there’s no program for the mbot that plays Africa. This had to be done. You’ll need mblock 5 for this file - select arduino mode.

or here’s the code

Summary

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

#include <MeMCore.h>

MeDCMotor motor_9(9);
MeDCMotor motor_10(10);

void move(int direction, int speed)
{
int leftSpeed = 0;
int rightSpeed = 0;
if(direction == 1){
leftSpeed = speed;
rightSpeed = speed;
}else if(direction == 2){
leftSpeed = -speed;
rightSpeed = -speed;
}else if(direction == 3){
leftSpeed = -speed;
rightSpeed = speed;
}else if(direction == 4){
leftSpeed = speed;
rightSpeed = -speed;
}
motor_9.run((9)==M1?-(leftSpeed):(leftSpeed));
motor_10.run((10)==M1?-(rightSpeed):(rightSpeed));
}

double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
MeBuzzer buzzer;

void setup(){

pinMode(A7,INPUT);

}

void loop(){

if((0^(analogRead(A7)>10?0:1))){
  for (int i=1;i<3;i++){
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 125);
    delay(20);
    buzzer.tone(392, 125);
    delay(20);
    buzzer.tone(392, 500);
    delay(20);
    for(int __i__=0;__i__<2;++__i__)
    {
        buzzer.tone(392, 250);
        delay(20);
    }
    buzzer.tone(440, 250);
    delay(20);
    buzzer.tone(494, 250);
    delay(20);
    buzzer.tone(523, 500);
    delay(20);
    _delay(0.3);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(330, 500);
    delay(20);
    buzzer.tone(330, 125);
    delay(20);
    buzzer.tone(294, 125);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(294, 500);
    delay(20);
    _delay(0.3);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(349, 500);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(440, 250);
    delay(20);
    buzzer.tone(494, 250);
    delay(20);
    buzzer.tone(523, 500);
    delay(20);
    _delay(0.2);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(330, 500);
    delay(20);
    buzzer.tone(330, 125);
    delay(20);
    buzzer.tone(294, 125);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(294, 500);
    delay(20);
    _delay(0.3);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(349, 500);
    delay(20);
    _delay(0.2);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(440, 250);
    delay(20);
    buzzer.tone(494, 250);
    delay(20);
    buzzer.tone(523, 500);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(330, 125);
    delay(20);
    buzzer.tone(330, 125);
    delay(20);
    buzzer.tone(330, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(349, 250);
    delay(20);
    buzzer.tone(349, 125);
    delay(20);
    buzzer.tone(330, 125);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(330, 500);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(294, 500);
    delay(20);
    _delay(0.3);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(349, 500);
    delay(20);
    _delay(0.3);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(392, 250);
    delay(20);
    buzzer.tone(440, 250);
    delay(20);
    buzzer.tone(494, 250);
    delay(20);
    buzzer.tone(523, 500);
    delay(20);
    _delay(0.3);
    buzzer.tone(659, 250);
    delay(20);
    buzzer.tone(659, 250);
    delay(20);
    buzzer.tone(698, 250);
    delay(20);
    buzzer.tone(784, 250);
    delay(20);
    buzzer.tone(784, 250);
    delay(20);
    buzzer.tone(698, 250);
    delay(20);
    buzzer.tone(698, 125);
    delay(20);
    buzzer.tone(659, 125);
    delay(20);
    buzzer.tone(698, 250);
    delay(20);
    buzzer.tone(698, 500);
    delay(20);
    _delay(1);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 500);
    delay(20);
    buzzer.tone(880, 250);
    delay(20);
    buzzer.tone(880, 1000);
    delay(20);
    _delay(0.2);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(880, 250);
    delay(20);
    buzzer.tone(880, 1000);
    delay(20);
    _delay(0.2);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 500);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 500);
    delay(20);
    buzzer.tone(880, 250);
    delay(20);
    buzzer.tone(880, 1000);
    delay(20);
    _delay(0.2);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(912, 250);
    delay(20);
    buzzer.tone(880, 250);
    delay(20);
    buzzer.tone(880, 500);
    delay(20);
    buzzer.tone(880, 125);
    delay(20);
    buzzer.tone(784, 125);
    delay(20);
    buzzer.tone(698, 125);
    delay(20);
    buzzer.tone(880, 500);
    delay(20);
    buzzer.tone(880, 125);
    delay(20);
    buzzer.tone(912, 125);
    delay(20);
    buzzer.tone(880, 250);
    delay(20);
    buzzer.tone(784, 500);
    delay(20);
    _delay(0.2);
    buzzer.tone(784, 500);
    delay(20);
    buzzer.tone(587, 250);
    delay(20);
    buzzer.tone(587, 125);
    delay(20);
    buzzer.tone(587, 500);
    delay(20);
    buzzer.tone(587, 250);
    delay(20);
    buzzer.tone(523, 250);
    delay(20);
    buzzer.tone(698, 500);
    delay(20);
    buzzer.tone(698, 1000);
    delay(20);
    _delay(0.6);
    buzzer.tone(587, 250);
    delay(20);
    buzzer.tone(587, 125);
    delay(20);
    buzzer.tone(587, 500);
    delay(20);
    buzzer.tone(587, 250);
    delay(20);
    buzzer.tone(523, 250);
    delay(20);
    buzzer.tone(698, 500);
    delay(20);
    buzzer.tone(698, 1000);
    delay(20);
    _delay(0.6);
    buzzer.tone(294, 1000);
    delay(20);
    buzzer.tone(294, 250);
    delay(20);
    buzzer.tone(262, 250);
    delay(20);
    buzzer.tone(349, 500);
    delay(20);
    buzzer.tone(349, 1000);
    delay(20);


}}

_loop();

}

void _delay(float seconds){
long endTime = millis() + seconds * 1000;
while(millis() < endTime)_loop();
}

void _loop(){

}


#2

Nice! I would like to mention that you can delete some of the upfront stuff to cut the program size down. The code is obviously generated by mBlock and inserts some boilerplate that isn’t really used in your program.

These header files are already included in the MeMCore.h header file:

====8< cut here >8====

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

==== cut here ====

If you’re not using motors, or calculating angles, this code isn’t needed:

====8< cut here >8====

MeDCMotor motor_9(9);
MeDCMotor motor_10(10);

void move(int direction, int speed)
{
int leftSpeed = 0;
int rightSpeed = 0;
if(direction == 1){
leftSpeed = speed;
rightSpeed = speed;
}else if(direction == 2){
leftSpeed = -speed;
rightSpeed = -speed;
}else if(direction == 3){
leftSpeed = -speed;
rightSpeed = speed;
}else if(direction == 4){
leftSpeed = speed;
rightSpeed = -speed;
}
motor_9.run((9)==M1?-(leftSpeed):(leftSpeed));
motor_10.run((10)==M1?-(rightSpeed):(rightSpeed));
}

double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;

====8< cut here >8====

Best regards,

Chuck


#3

Thanks! I’m not much into the mbot, so i just used the simple tools.


#4

This sounds cool. I will try is when I get home. Do I just paste the code into mBlock5


#5

Yes. Just select arduino c, paste the code then upload it to the robot. My only issue is that you can’t upload the default program from it. I actually have to go back to mblock 3 to do that.


#6

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