setting environment int variable in Linux for use in a while loop in python but loop doesn't stop -
i'm controlling led on raspberry pi 2 python. want led go on x seconds. when set environment variable in linux. example, export t=5
. led goes on won't go off.
if set variable in python script works fine.
i'm setting environment variable in linux so:
export t=5 sudo python test.py
and getting in python so:
#!/usr/bin/env python import rpi.gpio gpio import time import os gpio.setmode(gpio.board) gpio.setup(11,gpio.in, pull_up_down=gpio.pud_down) gpio.setup(12,gpio.out) gpio.output(12,0) s = 0 t = os.environ.get('t') while s <= t: if (gpio.input(11) == 1): gpio.output(12, 1) time.sleep(0.1) s += 0.1 else: gpio.output(12, 0) gpio.output(12, 0)
the values of environment variables — , values of os.environ
— stored strings. thus, need convert t
number in order comparison s
want:
t = int(os.environ.get('t'))
Comments
Post a Comment