rbbit 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ require 'rbbit.rb'
2
+
3
+ # プログレスバー
4
+
5
+ =begin
6
+ ・[A]ボタンでバーが伸長
7
+ ・[B]ボタンでバーが収縮
8
+ ・[A]+[B]同時押下で終了
9
+ =end
10
+
11
+ pattern = [
12
+ [ # 0
13
+ [0, 0, 0, 0, 0],
14
+ [0, 0, 0, 0, 0],
15
+ [0, 0, 0, 0, 0],
16
+ [0, 0, 0, 0, 0],
17
+ [0, 0, 0, 0, 0],
18
+ ],
19
+ [ # 1
20
+ [0, 0, 0, 0, 0],
21
+ [0, 0, 0, 0, 0],
22
+ [0, 0, 0, 0, 0],
23
+ [0, 0, 0, 0, 0],
24
+ [0, 0, 1, 0, 0],
25
+ ],
26
+ [ # 2
27
+ [0, 0, 0, 0, 0],
28
+ [0, 0, 0, 0, 0],
29
+ [0, 0, 0, 0, 0],
30
+ [0, 0, 0, 0, 0],
31
+ [0, 1, 1, 1, 0],
32
+ ],
33
+ [ # 3
34
+ [0, 0, 0, 0, 0],
35
+ [0, 0, 0, 0, 0],
36
+ [0, 0, 0, 0, 0],
37
+ [0, 0, 0, 0, 0],
38
+ [1, 1, 1, 1, 1],
39
+ ],
40
+ [ # 4
41
+ [0, 0, 0, 0, 0],
42
+ [0, 0, 0, 0, 0],
43
+ [0, 0, 0, 0, 0],
44
+ [0, 0, 1, 0, 0],
45
+ [1, 1, 1, 1, 1],
46
+ ],
47
+ [ # 5
48
+ [0, 0, 0, 0, 0],
49
+ [0, 0, 0, 0, 0],
50
+ [0, 0, 0, 0, 0],
51
+ [0, 1, 1, 1, 0],
52
+ [1, 1, 1, 1, 1],
53
+ ],
54
+ [ # 6
55
+ [0, 0, 0, 0, 0],
56
+ [0, 0, 0, 0, 0],
57
+ [0, 0, 0, 0, 0],
58
+ [1, 1, 1, 1, 1],
59
+ [1, 1, 1, 1, 1],
60
+ ],
61
+ [ # 7
62
+ [0, 0, 0, 0, 0],
63
+ [0, 0, 0, 0, 0],
64
+ [0, 0, 1, 0, 0],
65
+ [1, 1, 1, 1, 1],
66
+ [1, 1, 1, 1, 1],
67
+ ],
68
+ [ # 8
69
+ [0, 0, 0, 0, 0],
70
+ [0, 0, 0, 0, 0],
71
+ [0, 1, 1, 1, 0],
72
+ [1, 1, 1, 1, 1],
73
+ [1, 1, 1, 1, 1],
74
+ ],
75
+ [ # 9
76
+ [0, 0, 0, 0, 0],
77
+ [0, 0, 0, 0, 0],
78
+ [1, 1, 1, 1, 1],
79
+ [1, 1, 1, 1, 1],
80
+ [1, 1, 1, 1, 1],
81
+ ],
82
+ [ # 10
83
+ [0, 0, 0, 0, 0],
84
+ [0, 0, 1, 0, 0],
85
+ [1, 1, 1, 1, 1],
86
+ [1, 1, 1, 1, 1],
87
+ [1, 1, 1, 1, 1],
88
+ ],
89
+ [ # 11
90
+ [0, 0, 0, 0, 0],
91
+ [0, 1, 1, 1, 0],
92
+ [1, 1, 1, 1, 1],
93
+ [1, 1, 1, 1, 1],
94
+ [1, 1, 1, 1, 1],
95
+ ],
96
+ [ # 12
97
+ [0, 0, 0, 0, 0],
98
+ [1, 1, 1, 1, 1],
99
+ [1, 1, 1, 1, 1],
100
+ [1, 1, 1, 1, 1],
101
+ [1, 1, 1, 1, 1],
102
+ ],
103
+ [ # 13
104
+ [0, 0, 1, 0, 0],
105
+ [1, 1, 1, 1, 1],
106
+ [1, 1, 1, 1, 1],
107
+ [1, 1, 1, 1, 1],
108
+ [1, 1, 1, 1, 1],
109
+ ],
110
+ [ # 14
111
+ [0, 1, 1, 1, 0],
112
+ [1, 1, 1, 1, 1],
113
+ [1, 1, 1, 1, 1],
114
+ [1, 1, 1, 1, 1],
115
+ [1, 1, 1, 1, 1],
116
+ ],
117
+ [ # 15
118
+ [1, 1, 1, 1, 1],
119
+ [1, 1, 1, 1, 1],
120
+ [1, 1, 1, 1, 1],
121
+ [1, 1, 1, 1, 1],
122
+ [1, 1, 1, 1, 1],
123
+ ]
124
+ ]
125
+
126
+ mb = Rbbit::Microbit.new(ARGV[0])
127
+
128
+ level = 0
129
+
130
+ mb.on_press_a do
131
+ if mb.button_down?(:b)
132
+ mb.break
133
+ else
134
+ level += 1 if level < 15
135
+ mb.led_show(pattern[level])
136
+ end
137
+ end
138
+
139
+ mb.on_press_b do
140
+ if mb.button_down?(:a)
141
+ mb.break
142
+ else
143
+ level -= 1 if level > 0
144
+ mb.led_show(pattern[level])
145
+ end
146
+ end
147
+
148
+ puts "Please press 'button-A' or 'button-B'\n(exit to press both 'button-A' and 'button-B')"
149
+ mb.led_off
150
+ mb.mainloop {}
151
+
152
+ mb.puts("OK!")
153
+ mb.close(5000)
154
+
@@ -0,0 +1,325 @@
1
+ <!DOCTYPE html>
2
+ <html lang="ja">
3
+
4
+ <head>
5
+ <style>
6
+ /* ボタン表示エリア */
7
+ .leds {
8
+ margin : auto; /* 中央寄せ */
9
+ width : 60px; /* ボタンの横幅 */
10
+ }
11
+
12
+ /* チェックボックス */
13
+ .leds input[type="checkbox"] {
14
+ display : none; /* チェックボックス非表示 */
15
+ }
16
+ .leds input[type="checkbox"]:checked + label {
17
+ background : #ff0000; /* 背景色 */
18
+ box-shadow : 3px 3px 6px #888; /* 影付け */
19
+ }
20
+
21
+ /* チェックボックスのラベル */
22
+ .leds label {
23
+ background : #eee; /* 背景色 */
24
+ display : block; /* ボックス要素に変更 */
25
+ box-sizing : border-box; /* 枠線を含んだサイズ */
26
+ border : 2px solid #ccc; /* 枠線(一旦四方向) */
27
+ border-radius : 6px; /* 角丸 */
28
+ height : 60px; /* ボタンの高さ */
29
+ /*
30
+ text-align : center; /* 文字位置は中央 */
31
+ line-height : 60px; /* 文字の高さ */
32
+ font-size : 18px; /* 文字サイズ */
33
+ font-weight : bold; /* 太字 */
34
+ */
35
+ box-shadow : none; /* 影なし */
36
+ transition : .3s; /* ゆっくり変化 */
37
+ }
38
+ </style>
39
+
40
+ <script>
41
+ let ws; // WebSocket
42
+
43
+ (function init() {
44
+ ws = new WebSocket("ws://127.0.0.1:50215");
45
+ ws.onmessage = (evt) => {
46
+ // $("#msg").append("<p>"+evt.data+"</p>");
47
+ // console.log(evt.data);
48
+ };
49
+
50
+ ws.onclose = () => {
51
+ console.log("Disconnected from server")
52
+ };
53
+
54
+ ws.onopen = () => {
55
+ ws.send("Connected to server");
56
+ };
57
+ })();
58
+
59
+ function plot(x, y, value) {
60
+ console.log(ws);
61
+ console.log(x, y, value);
62
+ let cmd = (value ? "on" : "off");
63
+ data = `{"command": "${cmd}", "arg1": "${x}", "arg2": "${y}"}`
64
+ console.log(data);
65
+ ws.send(data)
66
+ }
67
+
68
+ function allplot(value) {
69
+ let checkboxes = document.getElementsByTagName('input');
70
+ for (let i = 0; i < checkboxes.length; i++) {
71
+ if (checkboxes[i].type=='checkbox'){
72
+ checkboxes[i].checked = value;
73
+ }
74
+ }
75
+ let cmd = (value ? "on" : "off");
76
+ data = `{"command": "${cmd}"}`
77
+ console.log(data);
78
+ ws.send(data)
79
+ }
80
+
81
+ function reverse() {
82
+ let pattern = [];
83
+ let line = [];
84
+ let inputs = document.getElementsByTagName('input');
85
+ for (let i = 0; i < inputs.length; i++) {
86
+ if (inputs[i].type=='checkbox'){ // target is only 'checkbox'
87
+ inputs[i].checked = !inputs[i].checked;
88
+ line.push((inputs[i].checked ? 1 : 0)); // add 1 or 0 to line
89
+ if (line.length == 5) {
90
+ pattern.push(line); // add line to pattern to make 2D-Array
91
+ line = [];
92
+ }
93
+ }
94
+ }
95
+ data = `{"command": "show", "arg1": ${JSON.stringify(pattern)}}`
96
+ console.log(data);
97
+ ws.send(data)
98
+ }
99
+ </script>
100
+ </head>
101
+
102
+ <body>
103
+ <h1>micro:bit [LED panel]</h1>
104
+ <p>
105
+ <input type="button" value="All ON" onclick="allplot(true);">
106
+ <input type="button" value="All OFF" onclick="allplot(false);">
107
+ <input type="button" value="Reverse" onclick="reverse();">
108
+ </p>
109
+
110
+ <!-- LEDS -->
111
+ <table>
112
+ <tr>
113
+ <td>
114
+ <div class="leds">
115
+ <input type="checkbox" id="led00" value="00" onChange="plot(0, 0, this.checked)">
116
+ <label for="led00">
117
+ <span></span>
118
+ </label>
119
+ </div>
120
+ </td>
121
+ <td>
122
+ <div class="leds">
123
+ <input type="checkbox" id="led10" value="10" onChange="plot(1, 0, this.checked)">
124
+ <label for="led10">
125
+ <span></span>
126
+ </label>
127
+ </div>
128
+ </td>
129
+ <td>
130
+ <div class="leds">
131
+ <input type="checkbox" id="led20" value="20" onChange="plot(2, 0, this.checked)">
132
+ <label for="led20">
133
+ <span></span>
134
+ </label>
135
+ </div>
136
+ </td>
137
+ <td>
138
+ <div class="leds">
139
+ <input type="checkbox" id="led30" value="30" onChange="plot(3, 0, this.checked)">
140
+ <label for="led30">
141
+ <span></span>
142
+ </label>
143
+ </div>
144
+ </td>
145
+ <td>
146
+ <div class="leds">
147
+ <input type="checkbox" id="led40" value="40" onChange="plot(4, 0, this.checked)">
148
+ <label for="led40">
149
+ <span></span>
150
+ </label>
151
+ </div>
152
+ </td>
153
+ </tr>
154
+ <tr>
155
+ <td>
156
+ <div class="leds">
157
+ <input type="checkbox" id="led01" value="01" onChange="plot(0, 1, this.checked)">
158
+ <label for="led01">
159
+ <span></span>
160
+ </label>
161
+ </div>
162
+ </td>
163
+ <td>
164
+ <div class="leds">
165
+ <input type="checkbox" id="led11" value="11" onChange="plot(1, 1, this.checked)">
166
+ <label for="led11">
167
+ <span></span>
168
+ </label>
169
+ </div>
170
+ </td>
171
+ <td>
172
+ <div class="leds">
173
+ <input type="checkbox" id="led21" value="21" onChange="plot(2, 1, this.checked)">
174
+ <label for="led21">
175
+ <span></span>
176
+ </label>
177
+ </div>
178
+ </td>
179
+ <td>
180
+ <div class="leds">
181
+ <input type="checkbox" id="led31" value="31" onChange="plot(3, 1, this.checked)">
182
+ <label for="led31">
183
+ <span></span>
184
+ </label>
185
+ </div>
186
+ </td>
187
+ <td>
188
+ <div class="leds">
189
+ <input type="checkbox" id="led41" value="41" onChange="plot(4, 1, this.checked)">
190
+ <label for="led41">
191
+ <span></span>
192
+ </label>
193
+ </div>
194
+ </td>
195
+ </tr>
196
+ <tr>
197
+ <td>
198
+ <div class="leds">
199
+ <input type="checkbox" id="led02" value="02" onChange="plot(0, 2, this.checked)">
200
+ <label for="led02">
201
+ <span></span>
202
+ </label>
203
+ </div>
204
+ </td>
205
+ <td>
206
+ <div class="leds">
207
+ <input type="checkbox" id="led12" value="12" onChange="plot(1, 2, this.checked)">
208
+ <label for="led12">
209
+ <span></span>
210
+ </label>
211
+ </div>
212
+ </td>
213
+ <td>
214
+ <div class="leds">
215
+ <input type="checkbox" id="led22" value="22" onChange="plot(2, 2, this.checked)">
216
+ <label for="led22">
217
+ <span></span>
218
+ </label>
219
+ </div>
220
+ </td>
221
+ <td>
222
+ <div class="leds">
223
+ <input type="checkbox" id="led32" value="32" onChange="plot(3, 2, this.checked)">
224
+ <label for="led32">
225
+ <span></span>
226
+ </label>
227
+ </div>
228
+ </td>
229
+ <td>
230
+ <div class="leds">
231
+ <input type="checkbox" id="led42" value="42" onChange="plot(4, 2, this.checked)">
232
+ <label for="led42">
233
+ <span></span>
234
+ </label>
235
+ </div>
236
+ </td>
237
+ </tr>
238
+ <tr>
239
+ <td>
240
+ <div class="leds">
241
+ <input type="checkbox" id="led03" value="03" onChange="plot(0, 3, this.checked)">
242
+ <label for="led03">
243
+ <span></span>
244
+ </label>
245
+ </div>
246
+ </td>
247
+ <td>
248
+ <div class="leds">
249
+ <input type="checkbox" id="led13" value="13" onChange="plot(1, 3, this.checked)">
250
+ <label for="led13">
251
+ <span></span>
252
+ </label>
253
+ </div>
254
+ </td>
255
+ <td>
256
+ <div class="leds">
257
+ <input type="checkbox" id="led23" value="23" onChange="plot(2, 3, this.checked)">
258
+ <label for="led23">
259
+ <span></span>
260
+ </label>
261
+ </div>
262
+ </td>
263
+ <td>
264
+ <div class="leds">
265
+ <input type="checkbox" id="led33" value="33" onChange="plot(3, 3, this.checked)">
266
+ <label for="led33">
267
+ <span></span>
268
+ </label>
269
+ </div>
270
+ </td>
271
+ <td>
272
+ <div class="leds">
273
+ <input type="checkbox" id="led43" value="43" onChange="plot(4, 3, this.checked)">
274
+ <label for="led43">
275
+ <span></span>
276
+ </label>
277
+ </div>
278
+ </td>
279
+ </tr>
280
+ <tr>
281
+ <td>
282
+ <div class="leds">
283
+ <input type="checkbox" id="led04" value="04" onChange="plot(0, 4, this.checked)">
284
+ <label for="led04">
285
+ <span></span>
286
+ </label>
287
+ </div>
288
+ </td>
289
+ <td>
290
+ <div class="leds">
291
+ <input type="checkbox" id="led14" value="14" onChange="plot(1, 4, this.checked)">
292
+ <label for="led14">
293
+ <span></span>
294
+ </label>
295
+ </div>
296
+ </td>
297
+ <td>
298
+ <div class="leds">
299
+ <input type="checkbox" id="led24" value="24" onChange="plot(2, 4, this.checked)">
300
+ <label for="led24">
301
+ <span></span>
302
+ </label>
303
+ </div>
304
+ </td>
305
+ <td>
306
+ <div class="leds">
307
+ <input type="checkbox" id="led34" value="34" onChange="plot(3, 4, this.checked)">
308
+ <label for="led34">
309
+ <span></span>
310
+ </label>
311
+ </div>
312
+ </td>
313
+ <td>
314
+ <div class="leds">
315
+ <input type="checkbox" id="led44" value="44" onChange="plot(4, 4, this.checked)">
316
+ <label for="led44">
317
+ <span></span>
318
+ </label>
319
+ </div>
320
+ </td>
321
+ </tr>
322
+ </table>
323
+
324
+ </body>
325
+ </html>