回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

小麦和小昆奔跑在幸福的赛道上 简单

头像 harkove 2019.06.23 839 0

在一个美丽的城市里,小昆和小麦进行了一场追求幸福的赛道比赛——两队在各自的赛道上进行分数耐力赛,同时他们需要沿途将遗失的能源推入能源收集器内。

模拟了一场闯关后,并收集遗失的资源,学习有趣的颜色\石头剪刀布关卡小游戏,翻山越岭,最后推倒多米诺骨牌砸到福字的3D打印的模型,主要运用了麦昆小车的巡线模块,挑战了对赛道的制造能力和想象力使整个幸福赛道上增加了比赛的趣味性。

project-image

一、亮点:

1)设计目标:设置圆圈作能源(即绿、蓝、红圆圈),在过桥转弯后将能源推入框内(能源收集器),目标完成,获得一定分数。

2)在某转弯处设置一定的斜坡,斜坡添加大型障碍,推下障碍即可得分。

3)在终点设置多米诺骨牌,最先撞倒并砸到福字的3D打印的模型的赛车得分,比赛结束。

4)两车同时进行比赛,赛道添加桥梁,添加了得分制度,增加了比赛的难度,更增加了比赛的趣味性。

二、难点:

1)在桥上沿着巡线转弯时可能掉出桥外或者出现bug。

2)能源被挤下桥梁后可能会弹出能源收集器范围外。

3)上桥的坡度过大,容易翻车。

4)过拱门

三、难点克服:

1)设置挡板,增大转弯处的面积。

2)在能源框边缘增加挡板。

3)坡度减缓,将巡线拉直,增大桥的面积。

步骤1 1)多米诺骨牌:如你所见,在多米诺骨牌的设计上加上一些创意。 2)侧面斜坡:赛车场的赛道转弯时防止离心力翻车的斜坡加上巡线得成。 3)目标圆圈:模拟能源,将圆圈推入框内(能源收集器),获得一定分数。

材料清单

  • 麦昆小车 X3
  • microbit X6
  • microbit circular RGB expansion boardv2.0 X1
  • dfrobot 舵机 X1
  • dfrobot color sensor X1
  • 自制走向幸福的地图(含9个纸质桥梁) X1
  • 模拟能源块 X4
  • 多米诺骨牌6个 X1
  • 模拟能源收集区(木质创意栅栏) X4
代码
小麦机器人程序
let hhh = 0
radio.setGroup(1)
let strip = neopixel.create(DigitalPin.P15, 4, NeoPixelMode.RGB_RGB)
let shit = hhh
basic.showIcon(IconNames.Yes)
music.playTone(523, music.beat(BeatFraction.Whole))
basic.showLeds(`
    # . . . #
    # . . . #
    # # # # #
    . # # # .
    . . # . .
    `)
basic.pause(100)
basic.showString("OK")
basic.showNumber(3)
basic.showNumber(2)
basic.showNumber(1)
basic.showString("go")
basic.forever(function () {
    basic.showLeds(`
        # . . . #
        . # . # .
        . . # . .
        . # . # .
        # . . . #
        `)
    basic.showLeds(`
        . # . . .
        . # . # #
        . . # . .
        # # . # .
        . . . # .
        `)
    basic.showLeds(`
        . . # . .
        . . # . .
        # # # # #
        . . # . .
        . . # . .
        `)
    basic.showLeds(`
        . . . # .
        # # . # .
        . . # . .
        . # . # #
        . # . . .
        `)
})
basic.forever(function () {
    if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 1 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 1) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, 150)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, 150)
        basic.pause(80)
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 0 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 0) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 255)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 255)
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 1 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 0) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 0)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 100)
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 0 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 1) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 100)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 0)
    }
})
basic.forever(function () {
    if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 0 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 0) {
    	
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 0 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 1) {
        music.playTone(784, music.beat(BeatFraction.Sixteenth))
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 1 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 0) {
        music.playTone(784, music.beat(BeatFraction.Sixteenth))
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 1 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 1) {
        music.playTone(784, music.beat(BeatFraction.Sixteenth))
    }
})
代码
小麦学习color模块程序
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 0) {
        strip.showColor(neopixel.colors(NeoPixelColors.Red))
    } else if (receivedNumber == 2) {
        strip.showColor(neopixel.colors(NeoPixelColors.Green))
    } else if (receivedNumber == 3) {
        strip.showColor(neopixel.colors(NeoPixelColors.Yellow))
    }
})
let strip: neopixel.Strip = null
radio.setGroup(1)
strip = neopixel.create(DigitalPin.P2, 24, NeoPixelMode.RGB)
basic.showLeds(`
    # . . . #
    # . . . #
    # # # # #
    . # # # .
    . . # . .
    `)
代码
小昆机器人程序
input.onButtonPressed(Button.B, function () {
    BSel = Math.randomRange(3, 5)
    shape[BSel - 3].showImage(0)
    radio.sendNumber(BSel)
})
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 888) {
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 255)
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 255)
    } else if (receivedNumber == 0) {
        maqueen.motorStopAll()
    }
})
let BSel = 0
let shape: Image[] = []
radio.setGroup(11)
shape = [images.createImage(`
    . . . . .
    . # # # .
    . # # # .
    . # # # .
    . . . . .
    `), images.createImage(`
    # . . . .
    . # . # #
    . . # # #
    . # . # #
    # . . . .
    `), images.createImage(`
    # # # # #
    # # # # #
    # # # # #
    # # # # #
    # # # # #
    `)]
basic.forever(function () {
    if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 1 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 1) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, 150)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, 150)
        basic.pause(80)
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 0 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 0) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 150)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 150)
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 1 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 0) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, 0)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 80)
    } else if (maqueen.readPatrol(maqueen.Patrol.PatrolLeft) == 0 && maqueen.readPatrol(maqueen.Patrol.PatrolRight) == 1) {
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 80)
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, 0)
    }
})
代码
闯关小游戏石头剪刀布,并判断与小麦机器人的输赢
input.onButtonPressed(Button.A, function () {
    ASel = Math.randomRange(0, 2)
    Shape[ASel].showImage(0)
})
radio.onReceivedNumber(function (receivedNumber) {
    BSel = receivedNumber
    if (BSel - ASel == 3) {
        basic.showLeds(`
            . . . . .
            # # # # #
            . . . . .
            # # # # #
            . . . . .
            `)
        basic.pause(100)
        basic.showString("Try again!")
    } else if (BSel - ASel == 2 || BSel - ASel == 5) {
        basic.showIcon(IconNames.Yes)
        basic.showString("YOU WIN!")
        radio.sendNumber(888)
    } else if (BSel - ASel == 1 || BSel - ASel == 4) {
        basic.showIcon(IconNames.No)
        basic.showString("Try again!")
    } else {
    	
    }
})
let BSel = 0
let ASel = 0
let Shape: Image[] = []
radio.setGroup(11)
basic.showString("WELCOME!")
basic.showLeds(`
    . . . . .
    . # # # .
    . # # # .
    . # # # .
    . . . . .
    `)
basic.showLeds(`
    . # . . #
    . # . # .
    . # # . .
    . # . # .
    . # . . #
    `)
basic.showLeds(`
    # # # # #
    # # # # #
    # # # # #
    # # # # #
    # # # # #
    `)
Shape = [images.createImage(`
    . . . . .
    . # # # .
    . # # # .
    . # # # .
    . . . . .
    `), images.createImage(`
    # . . . .
    . # . # #
    . . # # #
    . # . # #
    # . . . .
    `), images.createImage(`
    # # # # #
    # # # # #
    # # # # #
    # # # # #
    # # # # #
    `)]
代码
舵机关卡程序
radio.onReceivedNumber(function (receivedNumber) {
    if (receivedNumber == 1) {
        basic.showIcon(IconNames.Yes)
        pins.servoWritePin(AnalogPin.P1, 120)
    } else {
        basic.showIcon(IconNames.No)
        pins.servoWritePin(AnalogPin.P1, 180)
    }
})
radio.setGroup(1)
代码
遥控color及麦昆舵机的程序
input.onButtonPressed(Button.A, function () {
    radio.setGroup(1)
    radio.sendNumber(0)
})
input.onButtonPressed(Button.B, function () {
    radio.setGroup(1)
    radio.sendNumber(2)
})
input.onGesture(Gesture.EightG, function () {
    radio.setGroup(1)
    radio.sendNumber(1)
})
input.onButtonPressed(Button.AB, function () {
    radio.setGroup(1)
    radio.sendNumber(3)
})
radio.setGroup(1)
basic.showLeds(`
    # . . . #
    # . . . #
    # # # # #
    . # # # .
    . . # . .
    `)

评论

user-avatar