Skip to content

Latest commit

 

History

History
175 lines (153 loc) · 7.3 KB

wind-gr-5-lesson.md

File metadata and controls

175 lines (153 loc) · 7.3 KB

Powering the Future with Wind Energy

fwd-edu-breakout=github:climate-action-kits/pxt-fwd-edu/fwd-breakout
Dial=github:climate-action-kits/pxt-fwd-edu

Step 1 @showdialog

Welcome to Powering the Future with Wind Energy Coding Tutorial. built project

Step 2 @showdialog

In this tutorial we will code the Dial component to turn the wind turbine in the same direction as the Dial is being turned. Use the Dial's button function to stop the wind turbine.

Step 3 @showdialog

Turn on the Climate Action Kit board. breakout board

Step 4 @showhint

Click three dots besides |Download| button, and click on Connect Device. Next, follow the steps to pair your micro:bit. pair gif

Step 5 @showhint

Next, click the |Download| button to download the blank project to start-up the simulators.

Step 6 @showdialog

This is how the simulators should look after a successful download. You can see the Dial, the Touch and the Servo Motors along side the Pump. initial-dowload-gif

Step 7 @showhint

Look below the @boardname@ simulator to see the Climate Action Board and the connected sensors. Try turning the Dial on your project, the virtual simulator will react to it. wind

Step 8

Click ||fwdSensors:Sensors|| drag and drop ||fwdSensors:on dial1 turned difference|| block in workspace.

fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    })

Step 9

Right click ||fwdSensors:on dial1 turned difference|| block and duplicate. Note: New block will be grey. greyed out example

Step 10

Change the direction arrow of the greyed out ||fwdSensors:on dial1 turned difference|| block. Note: Greyed out block will turn green. dial direction

fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    })
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    })

Step 11

Click ||fwdSensors:Sensors|| drag and drop ||fwdSensors:on touch down|| block in workspace.

fwdSensors.touch.fwdOnTouch(jacdac.ButtonEvent.Down, function () {
    })
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    })
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    })

Step 12

Click ||fwdMotors:Motors|| drag and drop ||fwdMotors:set leftServo to 50 %|| inside ||fwdSensors:on dial1 turned difference|| block. Change ||fwdMotors:leftServo|| to ||fwdMotors:middleServo||.

fwdSensors.touch.fwdOnTouch(jacdac.ButtonEvent.Down, function () {
    })
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(50)
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    })

Step 13

Right click ||fwdMotors:set middleServo to 50 %|| block and duplicate. Drag and drop inside the second ||fwdSensors:on dial1 turned difference|| block.

fwdSensors.touch.fwdOnTouch(jacdac.ButtonEvent.Down, function () {
    })
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(50)
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(50)
})

Step 14

Click ||fwdSensors:Sensors||. Drag ||fwdSensors:dial1 absolute position|| oval block close to ||fwdMotors:set middleServo 50 %|| replace ||fwdMotors:50 %|| of ||fwdMotors:set middleServo 50 %|| block.

fwdSensors.touch.fwdOnTouch(jacdac.ButtonEvent.Down, function () {
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(fwdSensors.dial1.fwdPosition())
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(50)
})

Step 15

Click ||fwdSensors:Sensors||. Drag ||fwdSensors:dial1 absolute position|| oval block close to the second ||fwdMotors:set middleServo 50 %|| replace ||fwdMotors:50 %|| of ||fwdMotors:set middleServo 50 %|| block.

fwdSensors.touch.fwdOnTouch(jacdac.ButtonEvent.Down, function () {
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(fwdSensors.dial1.fwdPosition())
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(fwdSensors.dial1.fwdPosition())
})

Step 16

Click ||fwdMotors:Motors|| drag and drop ||fwdMotors:set leftServo 50 %|| block inside ||fwdSensors:on touch down|| block. Change ||fwdMotors:leftServo|| to ||fwdMotors:middleServo||.

fwdSensors.touch.fwdOnTouch(jacdac.ButtonEvent.Down, function () {
    fwdMotors.middleServo.fwdSetSpeed(50)
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(fwdSensors.dial1.fwdPosition())
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(fwdSensors.dial1.fwdPosition())
})

Step 17

Change speed of ||fwdMotors:set middleServo 50 %|| block inside ||fwdSensors:on touch down|| to ||0||.

fwdSensors.touch.fwdOnTouch(jacdac.ButtonEvent.Down, function () {
    fwdMotors.middleServo.fwdSetSpeed(0)
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(fwdSensors.dial1.fwdPosition())
})
fwdSensors.dial1.fwdOnDialTurned(fwdSensors.DialDirection.CCW, function (difference) {
    fwdMotors.middleServo.fwdSetSpeed(fwdSensors.dial1.fwdPosition())
})

Step 18 @showhint

|Download| and test your code. Click the bulb icon to see how the simulator shows the components working. dial-middleServo

Step 19 @showdialog

If after |Downloading| your project does not work please refer to the image and make sure your components are assigned correctly. correct-assignment

Step 20 @showdialog

Need help in assigning the right components to their simulators. Watch the video. final-download

Step 21 @showdialog

Congratulations on completing your Powering the Future with Wind Energy Project!

Step 22 @showdialog

After your project is complete go back to the lesson for more challenges and extensions.