![](https://static.wixstatic.com/media/afdc09_6ecc222f58bf432aa16dfb2bbaf433a2f000.jpg/v1/fill/w_1280,h_720,al_c,q_85,enc_avif,quality_auto/afdc09_6ecc222f58bf432aa16dfb2bbaf433a2f000.jpg)
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](https://static.wixstatic.com/media/afdc09_d5a0020a764c43f2966c7faa39949f86~mv2.png/v1/fill/w_372,h_561,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/telecomando-a.png)
![telecomando-b.png](https://static.wixstatic.com/media/afdc09_222308fc953c4b05b803dd57adf9d195~mv2.png/v1/fill/w_472,h_560,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/telecomando-b.png)
![telecomando-c.png](https://static.wixstatic.com/media/afdc09_25ed6c8fab4a4836a0d4f76742adcf19~mv2.png/v1/fill/w_424,h_453,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/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();
}