-
Notifications
You must be signed in to change notification settings - Fork 1
/
blueBitKit.ts
1415 lines (1232 loc) · 36.8 KB
/
blueBitKit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* @file blueBit Kit
* @brief Laplus's blueBit Kit makecode library.
*
* @more info see:(http://wiki.labplus.cn/index.php?title=bluebit)
* @copyright [Labplus](http://wiki.labplus.com), 2018
* @copyright GNU Lesser General Public License
* @author [tangliufeng]
* @date 2018.4.13
*/
enum joyButton {
//% block="A Button"
A_Button = 1,
//% block="B Button"
B_Button = 2,
//% block="C Button"
C_Button = 3,
//% block="D Button"
D_Button = 4
};
enum SHT20 {
//%block="temperature"
temperature = 1,
//%block="humidity"
humidity = 2
};
enum ColorSensor {
//%block="red"
red = 1,
//%block="green"
green = 2,
//%block="blue"
blue = 3
};
enum extendIO {
//%block="P0"
P0 = 0,
//%block="P1"
P1 = 1,
//%block="P2"
P2 = 2,
//%block="P3"
P3 = 3,
//%block="P4"
P4 = 4,
//%block="P5"
P5 = 5,
//%block="P6"
P6 = 6,
//%block="P7"
P7 = 7
};
enum extendIOMode {
//%block="outpout"
outpout = 0,
//%block="inpout"
inpout = 1
};
enum Scroll {
//%block="left"
left = 0,
//%block="right"
right = 1
};
enum MIDI_Note {
//%block="off"
OFF = 0,
//%block="on"
ON = 1
};
enum ComMon {
//%block="off"
OFF = 0,
//%block="on"
ON = 1
};
enum Rec_Play {
//%block="rec"
rec = 0,
//%block="play"
play = 1,
//%block="stop"
stop = 2
};
enum motor_status {
//%block="clock"
clock = 0,
//%block="anticlock"
anticlock = 1,
//%block="stop"
stop = 2
};
enum Rocker_axis {
//%block="X"
X = 0,
//%block="Y"
Y = 1
};
enum MP3 {
//%block="Start"
Start = 0,
//%block="Pause"
Pause = 1,
//%block="Stop"
Stop = 2
};
enum oledFont {
//%block="Font5X7"
Font5X7 = 0,
//%block="SONG16X16"
SONG16X16 = 1,
//%block="SONG24X24"
SONG24X24 = 2,
//%block="Consolas32X32"
Consolas32X32 = 4
};
/**
* Functions for blueBit Kit
*/
//% weight=10 color=#8A2BE2 icon="\uf042" block="blueBitKit"
namespace blueBitKit {
let INITPIN = false;
let LEDFREE = false;
function init_pin(): void {
pins.setPull(DigitalPin.P0, PinPullMode.PullNone);
pins.setPull(DigitalPin.P1, PinPullMode.PullNone);
pins.setPull(DigitalPin.P2, PinPullMode.PullNone);
pins.setPull(DigitalPin.P8, PinPullMode.PullNone);
}
function ledPinfree(): void {
led.enable(false);
pins.setPull(DigitalPin.P3, PinPullMode.PullNone);
pins.setPull(DigitalPin.P4, PinPullMode.PullNone);
pins.setPull(DigitalPin.P6, PinPullMode.PullNone);
pins.setPull(DigitalPin.P7, PinPullMode.PullNone);
pins.setPull(DigitalPin.P9, PinPullMode.PullNone);
pins.setPull(DigitalPin.P10, PinPullMode.PullNone);
}
function ifledPin(pin: number): boolean {
if (DigitalPin.P3 || DigitalPin.P4 || DigitalPin.P6 || DigitalPin.P7
|| DigitalPin.P9 || DigitalPin.P10) {
return true;
}
else
return false;
}
/**
*
*
*/
//% blockId=Button_Press block="ButtonPress by|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function ButtonPress(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=infrared_is_triggered block="Triggered the infrared proximity sensor by|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function infraredIsTriggered(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=sound_is_triggered block="sound sensor is triggered in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function soundIsTriggered(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=Track_is_Dark block="Track sensor detected black in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function TrackIsDark(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=shockSensor_is_Triggered block="Shock Sensor is triggered in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function shockSensor(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=get_Rfid block="Get the Rfid in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function getRfid(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=finger_Print block="Fingerprint verification passed in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function fingerPrint(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=Human_Infrared block="Human Infrared sensor is triggered in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function HumanInfrared(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=magnetic_Switch block="Magnetic switch is triggered in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function magneticSwitch(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
* @param pin , eg: P0
* @param value , eg: 1
*/
//% blockId=usbSwitch block="In|%pin|USB switch ON_OFF|%value"
//% value.min=0 value.max=1
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=89
//% blockGap=15
export function usbSwitch(pin: DigitalPin, value: number): void {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalWritePin(pin, value);
}
/**
* @param pin , eg: P0
* @param value , eg: 1
*/
//% blockId=FanSwitch block="In|%pin|Fan switch ON_OFF|%value"
//% value.min=0 value.max=1
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=89
//% blockGap=15
export function FanSwitch(pin: DigitalPin, value: number): void {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalWritePin(pin, value);
}
/**
* @param pin , eg: P0
* @param index , eg: ComMon.ON
*/
//% blockId=LaserSwitch block="In|%pin|Laser ON_OFF|%value"
//% value.min=0 value.max=1
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=89
//% blockGap=15
export function LaserSwitch(pin: DigitalPin, value: number): void {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalWritePin(pin, value);
}
/**
* Rec_or_Play module.
* @param status Rec or Play, eg: Rec_Play.rec
* @param rec P0~P20, eg: 0
* @param play P0~P20, eg: 1
*/
//% blockId=Rec_or_Play block="Recorder|%status|in RecPin|%rec|and PlayPin|%play"
//% status.fieldEditor="gridpicker" status.fieldOptions.columns=3 status.fieldOptions.width="300"
//% rec.fieldEditor="gridpicker" rec.fieldOptions.columns=3 rec.fieldOptions.width="300"
//% play.fieldEditor="gridpicker" play.fieldOptions.columns=3 play.fieldOptions.width="300"
//% weight=58
//% blockGap=15
export function Rec_or_Play(status: Rec_Play, rec: DigitalPin, play: DigitalPin): void {
//import { writeDigital } from "./blueBitKit";
//let writeDigital = new writeDigital();
if (status == 2) {
pins.digitalWritePin(rec, 0);
pins.digitalWritePin(play, 0);
}
if (status == 1) {
pins.digitalWritePin(rec, 0);
pins.digitalWritePin(play, 1);
}
if (status == 0) {
pins.digitalWritePin(rec, 1);
pins.digitalWritePin(play, 0);
}
return; //实测:pins.digitalWritePin()换成writeDigital()来return无效
} //结论: 要return属性(附参数) 不能写了函数直接return
/**
*
*
*/
//% blockId=LEDbrightness block="Set LED brightness in pin|%pin|to|%value"
//% value.min=0 value.max=1023
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=87
//% blockGap=40
export function LEDbrightness(pin: AnalogPin, value: number): void {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogWritePin(pin, value);
}
/**
* Motor_on_off module.
* @param status motor status, eg: motor_status.clock
* @param speed 0~1023, eg: 300
* @param ain1 P0~P20, eg: P1
* @param ain2 P0~P20, eg: P0
*/
//% blockId=Motor_on_off block="Set DC motor|%status|with|speed %speed|in|AIN1 %ain1|and|AIN2 %ain2"
//% status.fieldEditor="gridpicker" status.fieldOptions.columns=3 status.fieldOptions.width="300"
//% speed.min=0 speed.max=1023
//% ain1.fieldEditor="gridpicker" ain1.fieldOptions.columns=3 ain1.fieldOptions.width="300"
//% ain2.fieldEditor="gridpicker" ain2.fieldOptions.columns=3 ain2.fieldOptions.width="300"
//% weight=30
//% blockGap=15
export function Motor_on_off(status: motor_status, speed: number, ain1: AnalogPin, ain2: AnalogPin): void {
if (status == 2) { //停止
pins.analogWritePin(ain1, 1);
pins.analogWritePin(ain2, 1);
}
if (status == 1) { //反转
pins.analogWritePin(ain1, 1);
pins.analogWritePin(ain2, speed);
}
if (status == 0) { //正转
pins.analogWritePin(ain1, speed);
pins.analogWritePin(ain2, 1);
}
return;
}
/**
* read analog pin only pin0/1/2/3/4/10
*
*/
//% blockId=water_level block="Values of water level sensors in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=88
//% blockGap=15
export function water_level(pin: AnalogPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogReadPin(pin);
}
/**
* read analog pin only pin0/1/2/3/4/10
*/
//% blockId=Rotational_sensors block="Values of rotational potentiometer in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=88
//% blockGap=15
export function Rotational_sensors(pin: AnalogPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogReadPin(pin);
}
/**
* read analog pin only pin0/1/2/3/4/10
*/
//% blockId= sound_sensors block="Values of sound sensor in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=88
//% blockGap=15
export function sound_sensors(pin: AnalogPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogReadPin(pin);
}
/**
* read analog pin only pin0/1/2/3/4/10
*/
//% blockId= soil_moisture_sensor block="Values of soil moisture sensor in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=88
//% blockGap=15
export function soil_moisture_sensor(pin: AnalogPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogReadPin(pin);
}
/**
* read analog pin only pin0/1/2/3/4/10
*/
//% blockId= Analog_ray_sensor block="Values of Analog ray sensor in|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=88
//% blockGap=15
export function Analog_ray_sensor(pin: AnalogPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogReadPin(pin);
}
/**
* Rocker_sensor module.
* @param axis Rocker_axis, eg: Rocker_axis.X
* @param A0 P0/P1/P2/P3/P4/P10, eg: P1
* @param A1 P0/P1/P2/P3/P4/P10, eg: P0
*/
//% blockId=Rocker_sensor block="Value of rocker sensor in|%axis|in A0|%A0|in A1|%A1"
//% axis.fieldEditor="gridpicker" axis.fieldOptions.columns=3 axis.fieldOptions.width="300"
//% A0.fieldEditor="gridpicker" A0.fieldOptions.columns=3 A0.fieldOptions.width="300"
//% A1.fieldEditor="gridpicker" A1.fieldOptions.columns=3 A1.fieldOptions.width="300"
//% weight=58
//% blockGap=15
export function Rocker_sensor(axis: Rocker_axis, A0: AnalogPin, A1: AnalogPin): void {
if (axis == 0) { //摇杆传感器X轴
pins.analogReadPin(A1);
}
if (axis == 1) { //摇杆传感器Y轴
pins.analogReadPin(A0);
}
return;
}
/**
*
*
*/
//% blockId=read_digital block="bule:bit readDigital|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=90
//% blockGap=15
export function readDigital(pin: DigitalPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalReadPin(pin);
}
/**
*
*
*/
//% blockId=write_digital block="bule:bit writeDigital pin|%pin|to|%value"
//% value.min=0 value.max=1
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=89
//% blockGap=15
export function writeDigital(pin: DigitalPin, value: number): void {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.digitalWritePin(pin, value);
}
/**
* read analog pin only pin0/1/2/3/4/10
*
*/
//% blockId=read_analog block="bule:bit read analog|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=88
//% blockGap=15
export function readAnalog(pin: AnalogPin): number {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogReadPin(pin);
}
/**
*
*
*/
//% blockId=write_analog block="bule:bit writeAnalog pin|%pin|to|%value"
//% value.min=0 value.max=1023
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=87
//% blockGap=40
export function writeAnalog(pin: AnalogPin, value: number): void {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
return pins.analogWritePin(pin, value);
}
//% shim=blueBitKit::_getNTC
function _getNTC(value: number) {
// Dummy implementation for the simulator.
return 0;
}
/**
* blue:bit- NTC Temp module.
* return temperature,unit C.
*/
//% blockId=getNTC block="get NTCTemp|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=85
//% blockGap=15
export function getNTC(pin: AnalogPin): number {
return _getNTC(readAnalog(pin));
}
/**
* blue:bit-joy Button module.
* have A/B/C/D button,return 'true' if pressed; return'false' if not.
* read analog pin only pin0/1/2/3/4/10.
*/
//% blockId=joyButtonVal block="joyButton|%button|is pressed|pin|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% button.fieldEditor="gridpicker" button.fieldOptions.width=300 button.fieldOptions.columns=2
//% weight=84
//% blockGap=15
export function joyButtonVal(button: joyButton, pin: AnalogPin): boolean {
if (!INITPIN) {
init_pin();
INITPIN = true;
}
if (ifledPin(pin)) {
if (!LEDFREE) {
ledPinfree();
LEDFREE = true;
}
}
let status = false;
let val = readAnalog(pin);
switch (button) {
case 1: if (val < 51) {
status = true;
} break;
case 2: if (val > 199 && val < 301) {
status = true;
} break;
case 3: if (val > 449 && val < 551) {
status = true;
} break;
case 4: if (val > 669 && val < 801) {
status = true;
} break;
default:
break;
}
return status;
}
//% shim=blueBitKit::_getLM35
function _getLM35(value: number) {
// Dummy implementation for the simulator.
return 0;
}
/**
* blue:bit- LM35 Temp module.
* return temperature,unit ?.
* read analog pin only pin0/1/2/3/4/10.
*/
//% blockId=getLM35Temp block="get LM35Temp pin|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4 pin.fieldOptions.width="300"
//% weight=83
//% blockGap=15
export function getLM35Temp(pin: AnalogPin): number {
return _getLM35(readAnalog(pin));
}
/**
* blue:bit- HUMI&Temp module.
* return temperature(unit C ) and humidity (unit %).
* pin:I2C.
*/
//% blockId=getHumiTemp block="get HumiTemp|%index"
//% index.fieldEditor="gridpicker" index.fieldOptions.columns=1 index.fieldOptions.width="200"
//% weight=82
//% blockGap=15
//% shim=blueBitKit::_HumiTemp
export function getHumiTemp(index: SHT20): number {
// Fake function for simulator
return 0;
}
/**
* blue:bit- Ambient Light module.
* return LightValue(unit lux ).
* pin:I2C
*/
//% blockId=getAmbientLight block="get AmbientLight (lux)"
//% weight=81
//% blockGap=15
//% shim=blueBitKit::_getLight
export function getAmbientLight(): number {
// Fake function for simulator
return 0;
}
/**
* blue:bit- ultrasonic module.
* return distance(unit cm ).
* pin:I2C
*/
//% blockId=Ultrasonic block="get Ultrasonic (cm)"
//% weight=80
//% blockGap=15
//% shim=blueBitKit::_getDistance
export function Ultrasonic(): number {
// Fake function for simulator
return 0;
}
/**
* blue:bit- Color module.
* return red/green/blue ColorValue,Rang 0~255.
* pin:I2C.
*/
//% blockId=ColorSensor block="get ColorSensor|%index"
//% index.fieldEditor="gridpicker" index.fieldOptions.columns=3 index.fieldOptions.width="300"
//% weight=79
//% blockGap=50
//% shim=blueBitKit::_ColorSensor
export function ColorSensor(index: ColorSensor): number {
// Fake function for simulator
return 0;
}
/**
* blue:bit- 4x7 SEG Display module.
* display 4 Digits initialize.use SegDigits display before must be init.
* pin:I2C
*
*/
//% blockId=SegDigitsInit block="SegDigits initialize"
//% weight=77
//% blockGap=15
//% shim=blueBitKit::tm1650Init
export function SegDigitsInit(): void {
// Fake function for simulator
return;
}
/**
* blue:bit- 4x7 SEG Display module.
* display 4 Digits
* pin:I2C
* @param num eg:8888
*/
//% blockId=SegDigits_ block="SegDigits Display|%num"
//% weight=76
//% blockGap=15
//% shim=blueBitKit::tm1650DisplayInt
export function SegDigits_(num: number): void {
// Fake function for simulator
return;
}
/**
* blue:bit- 4x7 SEG Display module.
* display 4 Digits Clear
* pin:I2C
*
*/
//% blockId=SegDigitsClear block="SegDigits Clear"
//% weight=75
//% blockGap=30
//% shim=blueBitKit::tm1650Clear
export function SegDigitsClear(): void {
// Fake function for simulator
return;
}
/**
* blue:bit- 8x8 LED matrix module.
* 8x8 LED matrix initialize
* pin:I2C
*
*/
//% blockId=ledMatrixInit block="LED Matrix initialize "
//% weight=73
//% blockGap=15
//% shim=blueBitKit::HT16K33Init
export function ledMatrixInit(): void {
// Fake function for simulator
return;
}
/**
* blue:bit- 8x8 LED matrix module.
* 8x8 LED matrix Clear
* pin:I2C
*
*/