top of page

Maqueen plus Project

input.onButtonPressed(Button.A, function () {
DFRobotMaqueenPlus.mototRun(Motors.ALL, Dir.CW, 40)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBA, Color.GREEN)
basic.showNumber(1)
basic.pause(2000)
DFRobotMaqueenPlus.mototRun(Motors.ALL, Dir.CCW, 30)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBA, Color.RED)
basic.showNumber(2)
basic.pause(2000)
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 30)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBL, Color.BLUE)
basic.showNumber(3)
basic.pause(2000)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 30)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBR, Color.YELLOW)
basic.showNumber(4)
basic.pause(2000)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 40)
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CCW, 40)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBA, Color.PINK)
basic.showNumber(5)
basic.pause(2000)
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 40)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CCW, 40)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBA, Color.CYAN)
basic.showNumber(6)
basic.pause(2000)
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 30)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 40)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBL, Color.PINK)
basic.showNumber(7)
basic.pause(2000)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 30)
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 40)
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBR, Color.CYAN)
basic.showNumber(8)
basic.pause(2000)
})

basic.forever(function () {
if (DFRobotMaqueenPlus.readPatrol(Patrol.L1) == 1 && DFRobotMaqueenPlus.readPatrol(Patrol.R1) == 1) {
DFRobotMaqueenPlus.mototRun(Motors.ALL, Dir.CW, 40)
}
if (DFRobotMaqueenPlus.readPatrol(Patrol.L1) == 1 && DFRobotMaqueenPlus.readPatrol(Patrol.R1) == 0) {
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 40)
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 25)
}
if (DFRobotMaqueenPlus.readPatrol(Patrol.R1) == 1 && DFRobotMaqueenPlus.readPatrol(Patrol.L1) == 0) {
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 40)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 25)
}
if (DFRobotMaqueenPlus.readPatrol(Patrol.R1) == 0 && DFRobotMaqueenPlus.readPatrol(Patrol.L1) == 0) {
DFRobotMaqueenPlus.setRGBLight(RGBLight.RGBA, Color.RED)
DFRobotMaqueenPlus.mototRun(Motors.ALL, Dir.CCW, 30)
}
})

basic.forever(function () {
basic.showNumber(Math.round(DFRobotMaqueenPlus.ultraSonic(PIN.P1, PIN.P2) * 0.393701))
})

let direction = false
let U = 0
DFRobotMaqueenPlus.I2CInit()
DFRobotMaqueenPlus.PID(PID.OFF)
basic.forever(function () {
U = DFRobotMaqueenPlus.ultraSonic(PIN.P1, PIN.P2)
if (U < 40 && U != 0) {
direction = Math.randomBoolean()
if (direction == true) {
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 30)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 0)
basic.pause(1000)
} else {
DFRobotMaqueenPlus.mototRun(Motors.M1, Dir.CW, 0)
DFRobotMaqueenPlus.mototRun(Motors.M2, Dir.CW, 30)
basic.pause(1000)
}
} else {
DFRobotMaqueenPlus.mototRun(Motors.ALL, Dir.CW, 30)
}
})

Project Gallery

bottom of page