Skip to content

Commit 2c07157

Browse files
committed
Merge branch 'tutorials' into gh-pages
Conflicts: generators/tutorials.js
2 parents 1336e82 + 918b8d6 commit 2c07157

6 files changed

Lines changed: 177 additions & 0 deletions

File tree

blocks/tutorials.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,28 @@ Blockly.Blocks['button_game_user'] = {
538538
this.setHelpUrl('http://www.example.com/');
539539
}
540540
};
541+
542+
/*
543+
oooooooooo. ooooo ooooo ooooooooooooo
544+
`888' `Y8b `888' `888' 8' 888 `8
545+
888 888 888 888 888
546+
888 888 888ooooo888 888
547+
888 888 888 888 888
548+
888 d88' 888 888 888
549+
o888bood8P' o888o o888o o888o
550+
*/
551+
552+
// https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#iek22q
553+
Blockly.Blocks['tutorial_dht_show'] = {
554+
init: function() {
555+
this.appendValueInput("show")
556+
.appendField("顯示")
557+
.appendField(new Blockly.FieldDropdown([["溫度", "t"], ["濕度", "h"]]), "dht_")
558+
.appendField("為");
559+
this.setPreviousStatement(true);
560+
this.setNextStatement(true);
561+
this.setTooltip('');
562+
this.setColour(Blockly.Blocks.colour.HUE);
563+
this.setHelpUrl('http://www.example.com/');
564+
}
565+
};

generators/tutorials.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,26 @@ Blockly.JavaScript['button_game_user'] = function (block) {
437437
' }\n';
438438
return code;
439439
};
440+
441+
/*
442+
oooooooooo. ooooo ooooo ooooooooooooo
443+
`888' `Y8b `888' `888' 8' 888 `8
444+
888 888 888 888 888
445+
888 888 888ooooo888 888
446+
888 888 888 888 888
447+
888 d88' 888 888 888
448+
o888bood8P' o888o o888o o888o
449+
*/
450+
451+
Blockly.JavaScript['tutorial_dht_show'] = function (block) {
452+
var dropdown_dht_ = block.getFieldValue('dht_');
453+
var value_show = Blockly.JavaScript.valueToCode(block, 'show', Blockly.JavaScript.ORDER_ATOMIC);
454+
var code;
455+
if (dropdown_dht_ == "t") {
456+
code = 'document.getElementById("temperature").innerHTML = ' + value_show + ';\n'
457+
}
458+
if (dropdown_dht_ == "h") {
459+
code = 'document.getElementById("humidity").innerHTML = ' + value_show + ';\n'
460+
}
461+
return code;
462+
};

index-tutorials.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ <h4><a href="./?lang=zh-hant&page=tutorials/button-4" target="_blank">點擊按
165165
</li>
166166
</ul>
167167
<br/>
168+
<h3>溫濕度傳感器</h3>
169+
<ul>
170+
<li>
171+
<h4><a href="./?lang=zh-hant&page=tutorials/dht-1" target="_blank">偵測溫濕度</a></h4>
172+
( <a href="./?lang=zh-hant&page=tutorials/dht-1#-JvrZOa-PvI2vYJZdGrG" target="_blank">解答</a> )
173+
</li>
174+
</ul>
175+
<br/>
168176
<script>
169177
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
170178
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

msg/tutorials/dht-1/en.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MSG.backIndex = "Webduino Blockly Tutorials";
2+
MSG.demoTitle = "Blockly Demo Area";
3+
MSG.catTutorials = "Tutorials";
4+
MSG.timerVariable = "timer";
5+
6+
MSG.subTitle = "Chapter 5-1: DHT";
7+
MSG.demoDescription = "Use DHT sensor, return and displays the current temperature and humidity.";
8+
MSG.temperature = "temperature: ";
9+
MSG.humidity = "humidity: ";

msg/tutorials/dht-1/zh-hant.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MSG.backIndex = "Webduino 積木教學";
2+
MSG.demoTitle = "Blockly 範例測試區";
3+
MSG.catTutorials = "教學積木";
4+
MSG.timerVariable = "計時器";
5+
6+
MSG.subTitle = "課程 5-1:溫濕度傳感器";
7+
MSG.demoDescription = "使用溫濕度傳感器,回傳並顯示當前的溫度與濕度";
8+
MSG.temperature = "溫度:";
9+
MSG.humidity = "濕度:";

views/tutorials/dht-1.handlebars

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<link rel="stylesheet" href="tutorials.css">
2+
3+
<style>
4+
#show{
5+
font-size:40px;
6+
line-height: 50px;
7+
}
8+
#show b{
9+
display:inline-block;
10+
font-size:20px;
11+
vertical-align: top;
12+
13+
}
14+
</style>
15+
16+
<div id="demoArea">
17+
<div id="demoTitle">{{demoTitle}}</div>
18+
<div id="demoDescription">{{demoDescription}}</div>
19+
<div id="show">
20+
{{temperature}}<span id="temperature">0</span> <b>o</b>C<br/>
21+
{{humidity}}<span id="humidity">0</span> %
22+
</div>
23+
</div>
24+
<table width="60%" height="100%">
25+
<tr>
26+
<td>
27+
<h1>
28+
<a href="index-tutorials.html"><span id="backIndex">{{backIndex}}</span></a> >
29+
<span id="title">...</span><span id="subTitle">{{subTitle}}</span>
30+
</h1>
31+
</td>
32+
<td class="farSide">
33+
<select id="languageMenu"></select>
34+
</td>
35+
</tr>
36+
<tr>
37+
<td colspan=2>
38+
<table width="100%">
39+
<tr id="tabRow" height="1em">
40+
<td id="tab_blocks" class="tabon">{{blocks}}</td>
41+
<td class="tabmin">&nbsp;</td>
42+
<td id="tab_javascript" class="taboff">JavaScript</td>
43+
<td class="tabmin">&nbsp;</td>
44+
<td id="tab_xml" class="taboff" style="display:none;">XML</td>
45+
<td class="tabmax">
46+
<button id="trashButton" class="notext" title="{{trashTooltip}}">
47+
<img src='media/1x1.gif' class="trash icon21">
48+
</button>
49+
<button id="linkButton" class="notext" title="{{linkTooltip}}">
50+
<img src='media/1x1.gif' class="link icon21">
51+
</button>
52+
<button id="runButton" class="notext primary" title="{{runTooltip}}">
53+
<img src='media/1x1.gif' class="run icon21">
54+
</button>
55+
</td>
56+
</tr>
57+
</table>
58+
</td>
59+
</tr>
60+
<tr>
61+
<td height="99%" colspan=2 id="content_area">
62+
</td>
63+
</tr>
64+
</table>
65+
66+
<div id="content_blocks" class="content"></div>
67+
<pre id="content_javascript" class="content"></pre>
68+
<textarea id="content_xml" class="content" wrap="off"></textarea>
69+
70+
<xml id="toolbox" style="display: none">
71+
<category id="catVariables" custom="VARIABLE"></category>
72+
<sep></sep>
73+
<sep></sep>
74+
<category id="catBoard">
75+
<block type="board_ready">
76+
<value name="device_">
77+
<block type="text"></block>
78+
</value>
79+
</block>
80+
</category>
81+
<category id="catDht">
82+
<block type="variables_set">
83+
<field name="VAR">dht</field>
84+
<value name="VALUE">
85+
<block type="dht_new">
86+
<field name="pin_">11</field>
87+
</block>
88+
</value>
89+
</block>
90+
<block type="dht_get">
91+
<value name="time">
92+
<block type="math_number">
93+
<field name="NUM">1000</field>
94+
</block>
95+
</value>
96+
</block>
97+
<block type="dht_get_number"></block>
98+
</category>
99+
<category id="catTutorials">
100+
<block type="tutorial_dht_show"></block>
101+
</category>
102+
<sep></sep>
103+
</xml>

0 commit comments

Comments
 (0)