0

I'm trying to make a shutter speed variable based on a reading from an adafruit TSL2561 lux sensor. Lux is converted to an Exposure value using the equation in my code below, and then an shutter speed corresponds with the calculated EV (if aperture and ISO are constant).

I've tried assigning a shutter speed variable using an if command and a list, but I keep getting an error, saying:

"NameError: name 'shutterspeed' is not defined. 

I'm very new to Python and I'm sure there is a better way of doing this, I just don't know where to start.

ev1 = (math.log(ch2/2.5)/math.log(2))) + 3
ss = [32000, 16000, 8000, 4000, 2000, 1000, 500, 250]

if ev1 == 8:
    shutterspeed = ss[0]
if ev1 == 9:
    shutterspeed = ss[1]
if ev1 == 10:
    shutterspeed = ss[2]
if ev1 == 11:
    shutterspeed = ss[3]
if ev1 == 12:
    shutterspeed = ss[4]
if ev1 == 13: 
    shutterspeed = ss[5]
if ev1 == 14:
    shutterspeed = ss[6]
if ev1 == 15:
    shutterspeed = ss[7]
0

The error you produce is not reproducible by only this part of the code. But I'd probably skip all of the if statements and use something like:

shutterspeed = ss[ev1-8]

Assuming that you use the ev1 variable else ware, else you might as well decrease ev1 with 8 right away and use that variable.

  • thank you, it turns out some simple math was the easiest way to define the shutterspeed variable... – Daniel Smith Jan 28 '18 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.