Workshop Resource


Here's the code to get started

 


var smarti = require("Smartibot");

var dist = require("Smartibot-distance").connect(smarti.E1);

var int = 100;

var right = 300;

var left = 300;

setInterval(function() {

//Smooth out values from distance sensors to reduce noise

right = (right + dist.getRight())/2;

left = (left + dist.getLeft())/2;

// Send what we drew to the LED Matrix g.flip();

// If obstacle is less than 10cm from both sensors drive backwards

if (right < 200 || left < 200){

smarti.setMotor(1,0);

smarti.setMotor(2,0);

smarti.setServo(1,50);  
}

else if( right > 300 && left > 300 ){

smarti.setMotor(1,0.7);

smarti.setMotor(2,-0.7);

smarti.setServo(1,50);

int = 100; }

}, int);