Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/makecode/blocks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/makecode/blocksdiff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion main.blocks

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
def on_received_string(receivedString):
if receivedString == "LEDL":
DFRobotMaqueenPlusV2.set_index_color(0, NeoPixelColors.ORANGE)
elif receivedString == "LEDR":
DFRobotMaqueenPlusV2.set_index_color(2, NeoPixelColors.BLUE)
elif receivedString == "LEDALL":
DFRobotMaqueenPlusV2.led_rainbow(1, 360)
else:
DFRobotMaqueenPlusV2.control_motor_stop(MyEnumMotor.E_ALL_MOTOR)
radio.on_received_string(on_received_string)

def on_received_value(name, value):
global Blink
if name == "F":
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_ALL_MOTOR,
MyEnumDir.E_FORWARD,
Math.map(value, 550, 1023, 10, 255))
basic.show_arrow(ArrowNames.SOUTH)
Blink = 0
elif name == "B":
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_ALL_MOTOR,
MyEnumDir.E_BACKWARD,
Math.map(value, 0, 500, 255, 10))
basic.show_arrow(ArrowNames.NORTH)
Blink = 1
elif name == "L":
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_RIGHT_MOTOR,
MyEnumDir.E_FORWARD,
Math.map(value, 0, 450, 255, 40))
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_LEFT_MOTOR, MyEnumDir.E_FORWARD, 10)
basic.show_arrow(ArrowNames.EAST)
elif name == "R":
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_LEFT_MOTOR,
MyEnumDir.E_FORWARD,
Math.map(value, 600, 1023, 40, 255))
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_RIGHT_MOTOR, MyEnumDir.E_FORWARD, 10)
basic.show_arrow(ArrowNames.WEST)
elif name == "S":
DFRobotMaqueenPlusV2.control_motor_stop(MyEnumMotor.E_ALL_MOTOR)
DFRobotMaqueenPlusV2.show_color(NeoPixelColors.INDIGO)
else:
DFRobotMaqueenPlusV2.control_motor_stop(MyEnumMotor.E_ALL_MOTOR)
basic.clear_screen()
radio.on_received_value(on_received_value)

Index = 0
Blink = 0
DFRobotMaqueenPlusV2.i2c_init()
radio.set_group(200)
for Index2 in range(11):
music.play_melody("C D E F G F A C5 ", 2000)
Blink = 1
if input.light_level() < 100:
DFRobotMaqueenPlusV2.show_color(NeoPixelColors.WHITE)
DFRobotMaqueenPlusV2.control_motor_stop(MyEnumMotor.E_ALL_MOTOR)
basic.show_icon(IconNames.YES)
for Index3 in range(3):
basic.show_string("" + str(input.temperature()) + " ˘C")

def on_forever():
global Index
US = 0
Index = DFRobotMaqueenPlusV2.read_ultrasonic(DigitalPin.P13, DigitalPin.P14)
if US < 5 and US != 0:
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_LEFT_MOTOR, MyEnumDir.E_FORWARD, 50)
DFRobotMaqueenPlusV2.control_motor(MyEnumMotor.E_RIGHT_MOTOR, MyEnumDir.E_FORWARD, 5)
basic.forever(on_forever)

def on_in_background():
while True:
if Blink:
DFRobotMaqueenPlusV2.control_led(MyEnumLed.E_LEFT_LED, MyEnumSwitch.E_OPEN)
DFRobotMaqueenPlusV2.control_led(MyEnumLed.E_RIGHT_LED, MyEnumSwitch.E_CLOSE)
basic.pause(500)
DFRobotMaqueenPlusV2.control_led(MyEnumLed.E_LEFT_LED, MyEnumSwitch.E_CLOSE)
DFRobotMaqueenPlusV2.control_led(MyEnumLed.E_RIGHT_LED, MyEnumSwitch.E_OPEN)
basic.pause(500)
else:
DFRobotMaqueenPlusV2.control_led(MyEnumLed.E_ALL_LED, MyEnumSwitch.E_CLOSE)
basic.pause(500)
control.in_background(on_in_background)
34 changes: 24 additions & 10 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ radio.onReceivedValue(function (name, value) {
if (name == "F") {
DFRobotMaqueenPlusV2.controlMotor(MyEnumMotor.eAllMotor, MyEnumDir.eForward, Math.map(value, 550, 1023, 10, 255))
basic.showArrow(ArrowNames.South)
Blink = 0
} else if (name == "B") {
DFRobotMaqueenPlusV2.controlMotor(MyEnumMotor.eAllMotor, MyEnumDir.eBackward, Math.map(value, 0, 500, 255, 10))
basic.showArrow(ArrowNames.North)
Blink = 1
} else if (name == "L") {
DFRobotMaqueenPlusV2.controlMotor(MyEnumMotor.eRightMotor, MyEnumDir.eForward, Math.map(value, 0, 450, 255, 40))
DFRobotMaqueenPlusV2.controlMotor(MyEnumMotor.eLeftMotor, MyEnumDir.eForward, 10)
Expand All @@ -33,15 +35,21 @@ radio.onReceivedValue(function (name, value) {
}
})
let Index = 0
let Blink = 0
DFRobotMaqueenPlusV2.I2CInit()
radio.setGroup(200)
for (let Index2 = 0; Index2 <= 10; Index2++) {
for (let Index2 = 0; Index2 <= 5; Index2++) {
music.playMelody("C D E F G F A C5 ", 2000)
}
DFRobotMaqueenPlusV2.showColor(NeoPixelColors.White)
Blink = 1
if (input.lightLevel() < 80) {
DFRobotMaqueenPlusV2.showColor(NeoPixelColors.White)
}
DFRobotMaqueenPlusV2.controlMotorStop(MyEnumMotor.eAllMotor)
basic.showIcon(IconNames.Yes)
basic.showNumber(input.temperature())
for (let Index = 0; Index <= 2; Index++) {
basic.showString("" + input.temperature() + " °C")
}
basic.forever(function () {
let US = 0
Index = DFRobotMaqueenPlusV2.readUltrasonic(DigitalPin.P13, DigitalPin.P14)
Expand All @@ -51,11 +59,17 @@ basic.forever(function () {
}
})
control.inBackground(function () {
control.waitForEvent(12, 1)
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eLeftLed, MyEnumSwitch.eOpen)
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eRightLed, MyEnumSwitch.eClose)
basic.pause(500)
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eLeftLed, MyEnumSwitch.eClose)
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eRightLed, MyEnumSwitch.eOpen)
basic.pause(500)
while (true) {
if (Blink) {
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eLeftLed, MyEnumSwitch.eOpen)
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eRightLed, MyEnumSwitch.eClose)
basic.pause(500)
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eLeftLed, MyEnumSwitch.eClose)
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eRightLed, MyEnumSwitch.eOpen)
basic.pause(500)
} else {
DFRobotMaqueenPlusV2.controlLED(MyEnumLed.eAllLed, MyEnumSwitch.eClose)
basic.pause(500)
}
}
})
5 changes: 3 additions & 2 deletions pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
"main.ts",
".simstate.json",
".git.json",
"tutorial-info-cache.json"
"tutorial-info-cache.json",
"main.py"
],
"testFiles": [
"test.ts"
],
"targetVersions": {
"target": "5.0.12",
"target": "5.1.2",
"targetId": "microbit"
},
"supportedTargets": [
Expand Down