Things used in this project

Hardware components:
Microbitheart
BBC micro:bit board
×1
Infrared LED
High Power Infrared LED, 940 nm, e.g. SFH 4546 or TSAL 6200
×1
LEGO® 8884 - Power Function IR Receiver
×1
Software apps and online services:
Screen shot 2017 06 26 at 3 41 02 pm sfoohotutu
Microsoft MakeCode
pxt-powerfunctions
MakeCode package that provides Power Functions functionality on micro:bit devices
MakeCode Project
MakeCode project template with integrated Power Functions package

Code

JavaScript code example MakeCodeJavaScript
Use IR LED on P0.
Change direction of the motor on output blue on channel 1.
Plot light level
Stop train for 5 seconds if the light level is above a threshold.
Move forward for 3 seconds till next light level check.
powerfunctions.useIrLedPin(AnalogPin.P0)

powerfunctions.setMotorDirection(
  PowerFunctionsMotor.Blue1, 
  PowerFunctionsDirection.Backward
)
  
input.onButtonPressed(Button.A, () => {
    powerfunctions.moveForward(PowerFunctionsMotor.Blue1)
})

input.onButtonPressed(Button.B, () => {
    powerfunctions.float(PowerFunctionsMotor.Blue1)
})

basic.forever(() => {
    led.plotBarGraph(input.lightLevel(), 255)
    
    if (input.lightLevel() > 180) {
        powerfunctions.float(PowerFunctionsMotor.Blue1)
        basic.pause(5000)
        powerfunctions.setSpeed(PowerFunctionsMotor.Blue1, 2)
        basic.pause(3000)
    }
})

Credits

1853dd6acc4a3788e403c2fbfb04c0a4
Philipp Henkel
0 projects • 4 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / LoginAbout BBC micro:bit