@@ -300,6 +300,17 @@ class Neosoco(Robot):
300
300
301
301
_SERVO_STOP = 254
302
302
_SERVO_RESET_DEG = 186
303
+
304
+ _REMOTE_BTN_CVT = {
305
+ 'up' : 1 ,
306
+ 'down' : 2 ,
307
+ 'left' : 3 ,
308
+ 'right' : 4 ,
309
+ '1' : 10 ,
310
+ '2' : 11 ,
311
+ '3' : 12 ,
312
+ '4' : 13 ,
313
+ }
303
314
304
315
_robots = {}
305
316
@@ -472,7 +483,7 @@ def led_on(self, port='out1', brightness='100'):
472
483
else :
473
484
raise TypeError
474
485
475
- def led_off (self , port = 'port1 ' ):
486
+ def led_off (self , port = 'out1 ' ):
476
487
if isinstance (port , str ):
477
488
if port .lower () == 'out1' :
478
489
self .write (Neosoco .OUTPUT_1 , 0 )
@@ -692,19 +703,19 @@ def buzzer(self, pitch='3', note='c', beats='4'):
692
703
else :
693
704
pitch = Neosoco ._NOTES [note .lower ()] + (int (pitch ) - 1 ) * 12
694
705
if isinstance (pitch , (int , float )):
695
- cvt_dic = {
706
+ bpm_cvt = {
696
707
'2' : 1 ,
697
708
'4' : 0.5 ,
698
709
'8' : 0.25 ,
699
710
'16' : 0.125
700
711
}
701
- if beats in cvt_dic .keys ():
712
+ if beats in bpm_cvt .keys ():
702
713
bpm = self ._bpm # default 60
703
714
if note == 0 :
704
715
self .write (Neosoco .NOTE , Neosoco ._NOTE_OFF )
705
- Runner .wait (cvt_dic [beats ] * 60 * 1000.0 / bpm )
716
+ Runner .wait (bpm_cvt [beats ] * 60 * 1000.0 / bpm )
706
717
else :
707
- timeout = cvt_dic [beats ] * 60 * 1000.0 / bpm
718
+ timeout = bpm_cvt [beats ] * 60 * 1000.0 / bpm
708
719
tail = 0
709
720
if timeout > 100 :
710
721
tail = 100
@@ -723,3 +734,15 @@ def buzzer_by_port(self, port='in1'):
723
734
self .write (Neosoco .NOTE , value )
724
735
else :
725
736
raise TypeError
737
+
738
+ def remote_button (self , button = '1' ):
739
+ if isinstance (button , str ):
740
+ if button in self ._REMOTE_BTN_CVT .keys ():
741
+ if self ._REMOTE_BTN_CVT [button ] == self .read (Neosoco .REMOCTL ):
742
+ return True
743
+ else :
744
+ return False
745
+ else :
746
+ raise ValueError ('Wrong value of button' )
747
+ else :
748
+ raise TypeError
0 commit comments