top of page

COME FAR INSEGUIRE LE LINEE AL ROBOTTINO, PER ESEMPIO USANDO L'8 NERO IN DOTAZIONE

Per far spostare il robottino sulle linee nere dovrete utilizzare per la scrittura a blocchi il codice qui sotto riportato:

2-mbot.png

Invece per far spostare il robottino sulle linee nere 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>

 

MeLineFollower linefollower_2(2);

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

}

 

void _delay(float seconds) {

long endTime = millis() + seconds * 1000;

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

}

 

void setup() {

while(1) {

if((0 ? (3 == 0 ? linefollower_2.readSensors() == 0 :

(linefollower_2.readSensors() & 3) == 3) :

(3 == 0 ? linefollower_2.readSensors() == 3 :

(linefollower_2.readSensors() & 3) == 0))){

 

move(1, 50 / 100.0 * 255);

 

}else{

if((1 ? (2 == 0 ? linefollower_2.readSensors() == 0 :

(linefollower_2.readSensors() & 2) == 2) :

(2 == 0 ? linefollower_2.readSensors() == 3 :

(linefollower_2.readSensors() & 2) == 0))){

 

move(4, 50 / 100.0 * 255);

 

}else{

if((1 ? (1 == 0 ? linefollower_2.readSensors() == 0 :

(linefollower_2.readSensors() & 1) == 1) :

(1 == 0 ? linefollower_2.readSensors() == 3 :

(linefollower_2.readSensors() & 1) == 0))){

 

move(3, 50 / 100.0 * 255);

 

}

 

}

 

}

 

_loop();

}

 

}

 

void _loop() {

}

 

void loop() {

_loop();

}

Ecco un tutorial fatto da me

bottom of page