top of page

COME FAR SPOSTARE IL
ROBOTTINO CON
L'UTILIZZO DEL 
TELECOMANDO

Per far spostare il robottino con l'utilizzo del telecomando dovrete utilizzare per la scrittura a blocchi il codice qui sotto riportato:

telecomando-a.png
telecomando-b.png
telecomando-c.png

Invece per far spostare il robottino con l'utilizzo del telecomando dovrete utilizzare per la scrittura in arduino il codice qui sotto riportato:

// generated by mBlock5 for mBot

// codes make you happy

 

#include <MeMCore.h>

#include <Arduino.h>

#include <Wire.h>

#include <SoftwareSerial.h>

 

MeIR ir;

MeDCMotor motor_9(9);

MeDCMotor motor_10(10);

 

float velocit_C3_A0 = 0;

float lentissimissimo = 0;

float lentissimo = 0;

float lento = 0;

float tartaruga = 0;

float fermo = 0;

float medio = 0;

float lepre = 0;

float veloce = 0;

float velocissimo = 0;

float velocissimissimo = 0;

 

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));

}

 

void _delay(float seconds) {

long endTime = millis() + seconds * 1000;

while(millis() < endTime) _loop();

}

 

void setup() {

ir.begin();

velocit_C3_A0 = 200;

while(1) {

if(ir.keyPressed(69)){

 

move(2, 100 / 100.0 * 255);

_delay(2);

move(2, 0);

 

move(1, 100 / 100.0 * 255);

 

}else{

if(ir.keyPressed(70)){

 

motor_9.run(-1 * 100/100.0*255);

motor_10.run(0/100.0*255);

while(!(ir.keyPressed(68)))

{

_loop();

 

motor_9.run(-1 * 0/100.0*255);

motor_10.run(100/100.0*255);

 

}

 

}else{

if(ir.keyPressed(71)){

 

motor_9.run(-1 * 0/100.0*255);

motor_10.run(100/100.0*255);

while(!(ir.keyPressed(68)))

{

_loop();

 

motor_9.run(-1 * 100/100.0*255);

motor_10.run(0/100.0*255);

 

}

 

}else{

if(ir.keyPressed(64)){

 

move(1, velocit_C3_A0 / 100.0 * 255);

 

}else{

if(ir.keyPressed(25)){

 

move(2, velocit_C3_A0 / 100.0 * 255);

 

}else{

if(ir.keyPressed(7)){

 

move(3, 50 / 100.0 * 255);

_delay(0.7);

move(3, 0);

 

}else{

if(ir.keyPressed(9)){

 

move(4, 50 / 100.0 * 255);

_delay(0.7);

move(4, 0);

 

}else{

if(ir.keyPressed(22)){

 

move(1, 0 / 100.0 * 255);

 

}else{

if(ir.keyPressed(12)){

 

move(1, 20 / 100.0 * 255);

 

}else{

if(ir.keyPressed(24)){

 

move(1, 40 / 100.0 * 255);

 

}else{

if(ir.keyPressed(94)){

 

move(1, 60 / 100.0 * 255);

 

}else{

if(ir.keyPressed(8)){

 

move(1, 80 / 100.0 * 255);

 

}else{

if(ir.keyPressed(28)){

 

move(1, 100 / 100.0 * 255);

 

}else{

if(ir.keyPressed(90)){

 

move(1, 100 / 100.0 * 255);

 

}else{

if(ir.keyPressed(66)){

 

move(1, 100 / 100.0 * 255);

 

}else{

if(ir.keyPressed(82)){

 

move(1, 100 / 100.0 * 255);

 

}else{

if(ir.keyPressed(74)){

 

move(1, 100 / 100.0 * 255);

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

}

 

_loop();

}

 

}

 

void _loop() {

ir.loop();

}

 

void loop() {

_loop();

}

Ecco un tutorial fatto da me

bottom of page