@@ -450,6 +450,49 @@ def convert_scale(self, port='in1', omin=0, omax=255, tmin=0, tmax=100):
450
450
else :
451
451
raise TypeError
452
452
453
+ def check_color (self , port = 'in1' , color = 'white' ):
454
+ if isinstance (port and color , str ):
455
+ if port .lower () == 'in1' :
456
+ c_value = self .read (Neosoco .INPUT_1 )
457
+ elif port .lower () == 'in2' :
458
+ c_value = self .read (Neosoco .INPUT_2 )
459
+ elif port .lower () == 'in3' :
460
+ c_value = self .read (Neosoco .INPUT_3 )
461
+ else :
462
+ raise ValueError ("Wrong value of port" )
463
+
464
+ if not color .lower () in Neosoco ._COLORS .keys ():
465
+ raise ValueError ('Wrong value of color' )
466
+ if (c_value >= 10 and c_value <= 50 ):
467
+ if (color .lower () == self .COLOR_NAME_WHITE ):
468
+ return True
469
+ else :
470
+ return False
471
+ elif (c_value >= 51 and c_value <= 90 ):
472
+ if (color .lower () == self .COLOR_NAME_RED ):
473
+ return True
474
+ else :
475
+ return False
476
+ elif (c_value >= 91 and c_value <= 130 ):
477
+ if (color .lower () == self .COLOR_NAME_YELLOW ):
478
+ return True
479
+ else :
480
+ return False
481
+ elif (c_value >= 131 and c_value <= 170 ):
482
+ if (color .lower () == self .COLOR_NAME_GREEN ):
483
+ return True
484
+ else :
485
+ return False
486
+ elif (c_value >= 171 and c_value <= 210 ):
487
+ if (color .lower () == self .COLOR_NAME_BLUE ):
488
+ return True
489
+ else :
490
+ return False
491
+ else :
492
+ return False
493
+ else :
494
+ raise TypeError
495
+
453
496
def led_on (self , port = 'out1' , brightness = '100' ):
454
497
percent_cvt = {
455
498
'100' : 255 ,
@@ -746,8 +789,9 @@ def buzzer_by_port(self, port='in1'):
746
789
value = self ._convert_scale_from_input_port (port , 65 )
747
790
self .write (Neosoco .NOTE , value )
748
791
else :
792
+
749
793
raise TypeError
750
-
794
+
751
795
def buzzer_stop (self ):
752
796
self .write (Neosoco .NOTE , 0 )
753
797
@@ -761,4 +805,4 @@ def remote_button(self, button='1'):
761
805
else :
762
806
raise ValueError ('Wrong value of button' )
763
807
else :
764
- raise TypeError
808
+ raise TypeError
0 commit comments