Education and Teaching
Use IOBlockly with linkSprite.IO
Topic: Use IOBlockly with linkSprite.IO
(Read 1 time)
Use IOBlockly with linkSprite.IO
Aug 10, 2016, 04:41 am
Blockly is a completely visual programming language launched by Google in 2012,it is similar to Scratch,a MIT programming language for children.You can build applications with a graphical object,which is a similar way to play Lego blocks toys .
Every graphical object is a block of code and you can joint it together to create a simple function, then combine these functions together to build a program. The whole process only needs to use the mouse to drag, doesn't need to hit the keyboard.
Blockly is a graphical programming language which runs on Web pages. Users uses the way of drag and drop puzzle to develop applications without writing any code.
Recently, we use the Blockly editor to implement the remote programming on the equipment which has connected to LinkSpriteIO Cloud. Which means, we can use fully visual programming language to program the IoT equipment and achieve some functions what we want.
Next we will use the LinkNode D1 as node equipment, then connected it to IOT Cloud of LinkSpriteIO. Blockly Editor will get the button state of the node equipment from LinkSprite IO, and control the LED on the node equipment.
With this example, we will introduce how to use Blockly editor to program IoT device on LinkSpriteIO.
Create a device on LinkSpriteIO
Log in and enter the device list page.
Click the 'Create DIY Device' in the upper-right corner to enter the create device page.
Choose the 'Device Type' as '00'（Custom Device Type).
Type Device Name and Group Name ,remember the name of the device.
After the device is successfully created, create "switch" (button) and "light" (light) two fields (control and judgment status)
After the success of create device ,click the Blockly in the upper right corner ,enter the programming module of Blockly.
Set the Device that need to be programmed in the Blockly
Click the 'Web Demo area' in the upper right corner to choose the exchange page of 'Web' and'Blockly' .
Change "Choose" into "LinkSpriteIO"that you can get the pages of all the devices.
Note:You can control the lights on the device page by programming to achieve the synchronization with the LED device.
Select the device that need to be programmed by Group and Device Name, then you can change Blockly into current device and program it.
Blockly Graphical Programming
According to the picture , drag the various modules from the left column to program and interpret program, When the server is connected successfully, then set the led variable to LED property , and set the button to Button property. Query the value of a button every 1s, and when the state is 'on' , set the led lamp as 'on', otherwise set led light as'off'. It means that this button's state will control the LED. Of course, you can also add other logic to achieve the function what you want .
2.After complete Blockly programming , you can click the run button in the upper right corner to run the program.
Test the result of Programming
1.On the device which you are just created, input the parameter 'switch' as 0 or 1,then click the 'set' to input the parameters, view the status of the light . Whether to follow switch state change together ?
Introduce all modules
[Function]Connect with servers
[link] 'LinkSpriteIO'-> 'LED'
[Function]Get the LED light
[Function]Set state of LED as ON/OFF
[Function]What processes will be executed when the state of Led light is on/off.
[Attention]Because this is an operation which is executed immediately after the state of the led have changed , so you can not execute cycle of death or time consuming operation at that time, otherwise the program will enter a state of suspended animation
[Function]Get the state of Led(on/off),to judge the operation,usually it be used with 'if' module.
[Function]LED light flashing,the number is the time of flashing interval.
[Function]Exchange the state of LED light,when the state is 'on',change it to 'off',otherwise,change it to 'on'.
[Function]Get the state of button(on/off),to judge the operation,usually it be used with 'if' module.
[Function]What processes will be executed when the state of Button is on/off.
[Attention]Because this is an operation which is executed immediately after the state of the Button have changed , so you can not execute cycle of death or time consuming operation at that time, otherwise the program will enter a state of suspended animation
[Function]Cycle operation,once in a while,perform the operation after 'do'.it is similar to timer,once in a while, execute once.
[Function]The judgment condition module 'IF',if the conditions is established,operating the process after 'do'.
[Function] 'if..else'Click the set button in the upper right corner of 'if'module, it will shows as picture,drag 'else'module or 'if else'module to under 'if'module to composed process of 'if..else',when the condition was established,then perform the process of 'if' or 'do',otherwise perform the process after 'else'.
Change with website
[Link]Click the'Web Demo area' in the upper right corner to choose the exchange page of 'Web' and'Blockly', then get the pages of all the devices of users.
[Function]Get the page of all the devices of users.
[Link]'Web Demo"->"Click Button'
[Function]The control of light.