@@ -300,6 +300,17 @@ class Neosoco(Robot):
300300
301301 _SERVO_STOP = 254
302302 _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+ }
303314
304315 _robots = {}
305316
@@ -472,7 +483,7 @@ def led_on(self, port='out1', brightness='100'):
472483 else :
473484 raise TypeError
474485
475- def led_off (self , port = 'port1 ' ):
486+ def led_off (self , port = 'out1 ' ):
476487 if isinstance (port , str ):
477488 if port .lower () == 'out1' :
478489 self .write (Neosoco .OUTPUT_1 , 0 )
@@ -692,19 +703,19 @@ def buzzer(self, pitch='3', note='c', beats='4'):
692703 else :
693704 pitch = Neosoco ._NOTES [note .lower ()] + (int (pitch ) - 1 ) * 12
694705 if isinstance (pitch , (int , float )):
695- cvt_dic = {
706+ bpm_cvt = {
696707 '2' : 1 ,
697708 '4' : 0.5 ,
698709 '8' : 0.25 ,
699710 '16' : 0.125
700711 }
701- if beats in cvt_dic .keys ():
712+ if beats in bpm_cvt .keys ():
702713 bpm = self ._bpm # default 60
703714 if note == 0 :
704715 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 )
706717 else :
707- timeout = cvt_dic [beats ] * 60 * 1000.0 / bpm
718+ timeout = bpm_cvt [beats ] * 60 * 1000.0 / bpm
708719 tail = 0
709720 if timeout > 100 :
710721 tail = 100
@@ -723,3 +734,15 @@ def buzzer_by_port(self, port='in1'):
723734 self .write (Neosoco .NOTE , value )
724735 else :
725736 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