Created
June 27, 2017 18:40
-
-
Save thisandagain/e49202469bd52b35895505d47a556924 to your computer and use it in GitHub Desktop.
Scratch for the Tessel 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"objName": "Stage", | |
"sounds": [], | |
"costumes": [], | |
"children": [{ | |
"objName": "Sprite1", | |
"scripts": [ | |
[ | |
0, | |
0, | |
[ | |
["whenGreenFlag"], | |
["doForever", | |
[ | |
["broadcast:", "LED_ON"], | |
["wait:elapsed:from:", 0.1], | |
["broadcast:", "LED_OFF"], | |
["wait:elapsed:from:", 0.1] | |
] | |
] | |
] | |
] | |
], | |
"sounds": [], | |
"costumes": [], | |
"currentCostumeIndex": 0, | |
"scratchX": 0, | |
"scratchY": 0, | |
"scale": 1, | |
"direction": 180, | |
"rotationStyle": "normal", | |
"isDraggable": false, | |
"indexInLibrary": 1, | |
"visible": true, | |
"spriteInfo": {} | |
}], | |
"info": { | |
"spriteCount": 1, | |
"flashVersion": "MAC 21,0,0,174", | |
"swfVersion": "v445.1", | |
"videoOn": false, | |
"userAgent": "Scratch 2.0 Offline Editor", | |
"scriptCount": 4 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tessel = require('tessel'); | |
const VirtualMachine = require('scratch-vm'); | |
// Create VM instance and load project JSON | |
const vm = new VirtualMachine(); | |
const project = require('./test/fixtures/helloworld.json'); | |
// (Gross hack) inject opcode override for "broadcast" block | |
// @todo Replace with proper extensions system | |
vm.runtime._primitives['event_broadcast'] = function (args, util) { | |
console.log(args.BROADCAST_OPTION); | |
if (typeof tessel.led === 'undefined') return; | |
if (args.BROADCAST_OPTION === 'LED_ON') { | |
tessel.led[2].on(); | |
} | |
if (args.BROADCAST_OPTION === 'LED_OFF') { | |
tessel.led[2].off(); | |
} | |
}; | |
// Start VM | |
vm.start(); | |
vm.clear(); | |
vm.setCompatibilityMode(false); | |
vm.setTurboMode(false); | |
// Load project and simulate "green flag" event | |
vm.loadProject(JSON.stringify(project)).then(function () { | |
vm.greenFlag(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment