-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.blocks
1 lines (1 loc) · 7.08 KB
/
main.blocks
1
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="u;VRz0,):kFJX!z1%a]=">Rocket2</variable></variables><block type="pxt-on-start" id=":8WT|bnA#Yjgl0Agc^qJ" x="0" y="0"><statement name="HANDLER"><block type="typescript_statement" id="]Y.?MCFk]m,,+o*jItly" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="let rocket: rocketlauncher.rocket = null" numlines="1" declaredvars="rocket"></mutation><next><block type="typescript_statement" id="**:A6GX.IKA-?3mk84O9" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="enum RocketLaunchState {" line1=" //% block="Disarmed"" line2=" Disarmed," line3=" //% block="Armed"" line4=" Armed," line5=" //% block="Error"" line6=" Error" line7="}" numlines="8"></mutation><next><block type="typescript_statement" id="m:e$Nm8@Q2vv(6LB.[Vc" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="namespace rocketlauncher {" line1=" " line2="" line3="" line4=" export class rocket {" line5=" launchpin: DigitalPin;" line6=" countdown: number; // countdown in milliseconds" line7=" name: String;" line8=" mode: RocketLaunchState;" line9="" line10=" /**" line11=" * initiate the launch sequence." line12=" */" line13=" //% blockId="initiate-launch" block="%Rocket| launch" blockGap=8" line14=" //% rocket.defl=rocket" line15=" //% weight=79" line16=" //% parts="rocket"" line17=" initiateLaunch() {" line18=" if(this.mode==RocketLaunchState.Armed){" line19=" //start countdown" line20=" basic.pause(this.countdown);" line21=" //write pin 1 to HIGH " line22=" pins.digitalWritePin(this.launchpin, 1)" line23=" " line24=" // cooldown and shutdown" line25=" basic.pause(500);" line26=" pins.digitalWritePin(this.launchpin, 0)" line27=" }" line28=" else{" line29=" this.mode=RocketLaunchState.Error" line30=" }" line31=" }" line32="" line33=" /**" line34=" * Set the rocket state" line35=" * @param state" line36=" */" line37=" //% rocket.defl=rocket" line38=" //% blockId="set_rocket_state" block="Set %Rocket| state to %state"" line39=" //% weight=80 blockGap=8" line40=" setRocketState(state: RocketLaunchState): void {" line41=" this.mode = state" line42=" if (this.mode == RocketLaunchState.Armed) {" line43=" //write pin 0 to HIGH " line44=" " line45=" pins.digitalWritePin(DigitalPin.P0, 1)" line46=" }" line47=" else if (this.mode == RocketLaunchState.Disarmed) {" line48=" //write pin 0 to LOW" line49=" " line50=" pins.digitalWritePin(DigitalPin.P0, 0)" line51=" }" line52="" line53=" }" line54="" line55=" /**" line56=" * Rocket state" line57=" */" line58=" //% blockId=rocket_state block="%Rocket| is armed?"" line59=" //% parts="rocket"" line60=" isArmed(): boolean{" line61=" return(this.mode==RocketLaunchState.Armed)" line62="" line63=" }" line64="" line65="" line66=" }" line67="" line68="/**" line69=" * " line70=" * VISIBLE FUNCTIONS" line71=" * " line72=" */" line73="" line74=" /**" line75=" * Create a new rocket " line76=" * @param launchpin the pin where the rocket launch mechanism is conneted to." line77=" * @param countdown" line78=" * @param RocketLaunchState" line79=" */" line80=" //% blockId="rocket_create" block="Initialize rocket|on launchpin %launchpin|with launch delay %countdown|pre-arm state %RocketLaunchState"" line81=" //% weight=90 blockGap=8" line82=" //% parts="rocket"" line83=" //% trackArgs=0,2" line84=" //% blockSetVariable=rocket" line85=" export function create(launchpin: DigitalPin,countdown:number, mode: RocketLaunchState): rocket {" line86=" let r = new rocket();" line87=" r.launchpin = launchpin" line88=" r.countdown = countdown" line89=" r.mode = mode" line90=" return r;" line91=" }" line92="" line93="" line94="" line95=" " line96="}" numlines="97"></mutation><next><block type="variables_set" id="AeIMymlunQe7}I?Jgh_b"><field name="VAR" id="u;VRz0,):kFJX!z1%a]=">Rocket2</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="rocket_create" id="@|B+7+Oh2MjW0@gd2ifc"><field name="launchpin">DigitalPin.P2</field><field name="RocketLaunchState">RocketLaunchState.Disarmed</field><value name="countdown"><shadow type="math_number" id="J~37Uzk/8r)h9{_*Hv$Q"><field name="NUM">1500</field></shadow></value></block></value></block></next></block></next></block></next></block></statement></block><block type="device_button_event" id="*QpSV91$4[mMg%e4ECxR" x="10" y="4381"><field name="NAME">Button.A</field><statement name="HANDLER"><block type="set_rocket_state" id="(K8*Fgbnj-@y%1Nggmx9"><field name="state">RocketLaunchState.Armed</field><value name="Rocket"><block type="variables_get" id="tq(Q:4%Nd9:5zAR-k~Nq"><field name="VAR" id="u;VRz0,):kFJX!z1%a]=">Rocket2</field></block></value></block></statement></block><block type="every_interval" id="[*Pln3e~O=hd60}2Wd|3" x="706" y="4412"><value name="interval"><shadow type="longTimePicker" id="3IiQlcXN4+W)QBY:sbc["><field name="ms">500</field></shadow></value><statement name="HANDLER"><block type="controls_if" id="Pu!g3)*|{BHx4sW@^[q?"><mutation else="1"/><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="rocket_state" id="=JP`J5,9qzT7HB0h~(Di"><value name="Rocket"><block type="variables_get" id="^$`A4A~3^:~h;ac^Xy;4"><field name="VAR" id="u;VRz0,):kFJX!z1%a]=">Rocket2</field></block></value></block></value><statement name="DO0"><block type="basic_show_icon" id="iTAX-t8(N-G~Rcz|*Mby"><field name="i">IconNames.Yes</field></block></statement><statement name="ELSE"><block type="basic_show_icon" id="-^3}qx,cyC$/;5l_wUs7"><field name="i">IconNames.No</field></block></statement></block></statement></block><block type="device_button_event" id="@yjp2irHo18(wDcovh+." x="12" y="4525"><field name="NAME">Button.B</field><statement name="HANDLER"><block type="set_rocket_state" id="e0AONvhhHERPTUrd8;wE"><field name="state">RocketLaunchState.Disarmed</field><value name="Rocket"><block type="variables_get" id="dXR3iMWUSnjb*(/5F]*_"><field name="VAR" id="u;VRz0,):kFJX!z1%a]=">Rocket2</field></block></value></block></statement></block><block type="device_button_event" id="nr+ALG03%S8F-p2O`%Vc" x="16" y="4682"><field name="NAME">Button.AB</field><statement name="HANDLER"><block type="initiate-launch" id="l7ivHEimkl:q$iyq:V]z"><value name="Rocket"><block type="variables_get" id="_18D0at)`(vHM|J7#AP/"><field name="VAR" id="u;VRz0,):kFJX!z1%a]=">Rocket2</field></block></value></block></statement></block></xml>