Pysense light sensor if statement



  • Hello together, I need your help! I want to use the Light sensor from Pysense board. if the Light value lower than 10 --> go to deep sleep for a while

    if the value higher than 10 --> go forward and do the job ;-)

    but I can't use the lt.light() because the result is i.E. (102, 111) (red and blue channel)

    can anyone help me please?

    print("Light (channel Blue lux, channel Red lux): " + str(lt.light()))
    print (lt.light())
    sunlight = lt.light()
    if lt.light() < 10:
        print(lt.light(), "its dark - nothing to do.")
    print("###SUN CHECK###")
    if lt.light() > 11:
        print(lt.light(), "Sunny day - gogogo.")
    print(sunlight)```
    
    
    output: 
    Light (channel Blue lux, channel Red lux): (0, 1)
    (0, 1)
    ###SUN CHECK###
    (0, 1)
    Acceleration: (-0.1680908, -0.1392822, 0.9906006)
    Roll: 9.753601
    Pitch: 7.89145
    Battery voltage: 4.872366


  • And it may be better to store the value in a variable instead of reading it all the time from the sensor.

    Reading all the time is slower, consumes more power and combinations of red and blue values may be strange, when light changes inbetween the readings.



  • @svonbentzel what do you expect to happen when the light value is 10 ;-)

    possibly your should use <= 10 or >= 11



  • @svonbentzel said in Pysense light sensor if statement:

    if lt.light()[0] < 10 and lt.light()[0] < 10:

    If is intentional that you check the same element of the tuple twice? Shouldn't if be for instance:
    if lt.light()[0] < 10 and lt.light()[1] < 10:
    and similar a few lines below?



  • solved:

    print (lt.light())
        if lt.light()[0] < 10 and lt.light()[0] < 10:
            print(lt.light(), "its dark - nothing to do.")
    
        print("###SUN CHECK###")
        if lt.light()[1] > 11 and lt.light()[1] > 11:
            print(lt.light(), "Sunny day - gogogo.")```


  • type of lt.light: <class 'tuple'>


Log in to reply
 

Pycom on Twitter