def __init__(self): self.pins = [GPIO(12), GPIO(13), GPIO(182)] # green, red, blue # thread, used to blink later self.blinker_thread = None # to stop blinker later self.blinker_not_interrupted = True # keep current state in order to restore later self.current_blink_pattern = "" self.colors_dict = { "off": [0, 0, 0], "red": [1, 0, 0], "green": [0, 1, 0], "blue": [0, 0, 1], "white": [1, 1, 1], "yellow": [1, 1, 0], "cyan": [0, 1, 1], "magenta": [1, 0, 1], "orange": [1, 0.4, 0], "weakred": [0.1, 0, 0] } # channel numbers self.pwm_channels = [0, 1, 2] # red, green, blue # first, we need to change the pin's pinmux to mode1 for pin in self.pins: pin.setPinmux("mode1") # then, export the 3 pwn channels if needed for ch in self.pwm_channels: if not os.path.exists(self.pwm_prefix + "/pwm" + str(ch)): with open(self.pwm_prefix + "export", "w") as f: f.write(str(ch)) # enable all of the channels for ch in self.pwm_channels: with open(self.pwm_prefix + "pwm" + str(ch) + "/enable", "w") as f: f.write("1") # set period for ch in self.pwm_channels: with open(self.pwm_prefix + "pwm" + str(ch) + "/period", "w") as f: f.write("1000000")
def __init__(self): self.button_state: bool = False self.gpio: GPIO = GPIO() self.gpio.bind_to(self.update_button_state) self.camera: Camera = Camera(video_device=0) Process(target=self.gpio.run).start()
from Signal import Signal from Turnout import Turnout json_data = open('/home/pi/elite-xpressnet/track/config.json') data = json.load(json_data) redis = redis.Redis() pi = {} gpio = {} output = {} for pi_in in data["piinterface"]: pi[pi_in["id"]] = PiInterface(pi_in["bus"]) for gpio_in in data["gpio"]: gpio[gpio_in["id"]] = GPIO(pi[gpio_in["pi_id"]], gpio_in["address"], gpio_in["bank"], gpio_in["mode"]) logging.debug(str(gpio_in["id"])) for s_in in data["signals"]: bits = s_in["id"].split(",") key = str(bits[0]) + "," + str(bits[1]) io = gpio[key] start_address = bits[2] output[s_in["id"]] = Signal(s_in["id"], io, s_in["pinOut"], start_address, s_in["aspects"]) io.addOutput(output[s_in["id"]]) for t_in in data["turnouts"]: bits = t_in["id"].split(",") key = str(bits[0]) + "," + str(bits[1]) io = gpio[key]
#!/usr/bin/python import sys sys.path.append('//usr/local/Python') from GPIO import GPIO import cgi import cgitb cgitb.enable() gpio = GPIO() gpio.Run()
# need this for GPIO's from GPIO import GPIO # filter F = {1: GPIO("UV_filter", 11)} # valves V = {3: GPIO("CO2_solenoid", 89), 4: GPIO("N2_solenoid", 10)} # miscellaneous M = { 1: GPIO("heater", 45), 2: GPIO("chiller", 44), 6: GPIO("fan_1", 70), 7: GPIO("fan_2", 71), 8: GPIO("O2_concentrator", 26), 18: GPIO("LED", 51) } # pumps P = { 1: GPIO("main_pump", 62), 2: GPIO("condensate_pump", 63), 3: GPIO("nutrient_1_dosing", 23), 4: GPIO("nutrient_2_dosing", 65), 5: GPIO("pH_dosing", 27), 6: GPIO("nutrient_1_circulation", 37), 7: GPIO("air_bubbler", 33), 8: GPIO("filter_pump", 61), 9: GPIO("nutrient_2_circulation", 86), 10: GPIO("humidifier_pump", 32),
def __init__(self,name='gpio',interval=0.1,hostname=""): httphandle.__init__(self,name,interval,hostname) self.gpio=GPIO()