Loop infinitely and monitor the light level. Light up the number of LEDs depending on the value within the range specified """ # Compute the ratio that relates the value to number of LEDS ratio = len(leds) / (maxr - minr) while True: nleds = int(ratio * (photo.value - minr)) leds_off(leds) for i in range(nleds): leds[i].on() time.sleep(interval) # Our program to run # How fast to blink the LED [seconds] interval = 0.15 # Create an array of LEDs led_pins = [26, 12, 16, 20, 21] leds = [] for pin in led_pins: leds.append(gpiozero.LED(pin)) # Create the photoresistor light = gpiozero.LightSensor(13) initialize(leds) # test_photoresistor(light) monitor_light(leds=leds, photo=light, maxr=0.95, minr=0.85)
import gpiozero as gp import tkinter as tk import sys, os, csv, datetime, cv2, platform, subprocess, time, threading from tkinter import ttk, messagebox from PIL import Image, ImageTk from ttkthemes import ThemedStyle from time import sleep #Hardware Variable names, always match to schematic with numbers. Change your pins if differen. S1 = gp.Button(25) #Counter switch S2 = gp.Button(8) # Reset Cases S3 = gp.Button(7) #Reset Primers S4 = gp.Button(24) #Binding prox switches M1 = gp.PWMOutputDevice(20, frequency=1) #Primer vibrator M2 = gp.PWMOutputDevice(21, frequency=1) #Powder Vibrator Ldr1 = gp.LightSensor(4) #Low Primer Ldr2 = gp.LightSensor(19) #Bullet Feeder Ldr3 = gp.LightSensor(26) #Case Feeder # For Passive buzzers use PWM. Active buzzers use Buzzer. Be wise that too high a # frequecy will peg out CPU. Buzzer = gp.PWMOutputDevice(18, frequency=1500) #If you relays operate backwards swap the active_high state (default is True). #Setting initial_value to false ensures relays start closed enstead of current state. Relay1 = gp.OutputDevice(6, initial_value=False, active_high=True) Relay2 = gp.OutputDevice(12, initial_value=False, active_high=True) #Note to self: the way this works is the csv is turned into a class. The class name is the list ID which is Recipe[n], #where N is the number of the recipe line with 0 being the first line. After that the heading can be use as a dot atribut, #IE Recipe[0].cartridge will give you the cartridge name of recipe 0. with open('3_3_Cartridge_Recipe.csv', 'r', newline='') as f: reader = csv.DictReader(f)
###https://gpiozero.readthedocs.io/en/stable/api_input.html ##IMPORTS GO HERE import os #Gerenciamento de arquivos import gpiozero #GPIO nova, sensores import bluetooth #Bluetooth import subprocess #processamento paralelo, shell import json #output em json para servidor import time #time.sleep, time.time import threading #MultiThreading import Adafruit_DHT #DHT11 lib ##SETUP ###Input waterSensor = gpiozero.Button(pin=22, pull_up=False) ##WATER SENSOR AS BUTTON ldr=gpiozero.LightSensor(pin=24) ##LDR as LightSensor sensor=Adafruit_DHT.DHT11 ##DHT from Lib ###OUTPUT waterValve = gpiozero.OutputDevice(pin=23, active_high=True, initial_value=False) red=gpiozero.LED(4) ##RED MEANS STOP green=gpiozero.LED(17) ##GREEN MEANS GO blue=gpiozero.LED(24) ##BLUE MEANS CRY ###Variables mac="10:3B:59:B1:B3:C8" #Endereço bluetooth android day, soil, ctrLogs = "day", "low", 1#LDR, SoilSensor, LogCounter freq, senscount = 60, 4 #Read Frequency, Number of Sensors ##FUNCTIONS
# encoding: utf-8 import gpiozero import time led = gpiozero.PWMLED(27) ldr = gpiozero.LightSensor(17) while True: if ldr.value >= 0.75: led.value = 0 # ne sveti elif ldr.value < 0.75 and ldr.value >= 0.5: led.value = 0.5 # sveti na pol else: led.value = 1 # sveti time.sleep(1)
# LED light bar with "ADC" input import gpiozero import time interval = 0.9 photo = gpiozero.LightSensor(4) leds = [21, 16, 12, 23] leds = [gpiozero.LED(led) for led in leds] while True: [led.off() for led in leds] v = photo.value print(v) for i in range(int(v * len(leds))): leds[i].on() time.sleep(interval)
import gpiozero as gp import tkinter as tk import time from tkinter import ttk S4 = gp.Button(24) #Binding Sensor Ldr3 = gp.LightSensor(19) #Case Feeder Buzzer = gp.PWMOutputDevice(18, frequency=6000) Relay2 = gp.OutputDevice(6, initial_value=False, active_high=True) Relay2.source = Ldr3 while True: pulsetime = 0 Ldr3.wait_for_light() time.sleep(0.1) while Ldr3.light_detected == True: time.sleep(0.2) pulsetime += 1 print(pulsetime) if pulsetime >= 15: Buzzer.pulse(n=1) if Ldr3.light_detected == False: Buzzer.off()
from tkinter import simpledialog, messagebox import gpiozero import time import threading """Tkinter Initialization""" main = Tk() main.title('Smart Lamp') main.geometry('370x220') main.resizable(width=FALSE, height=FALSE) """Raspberry Initialization""" ldrpin = 27 pirpin = 4 relaypin = 17 times = 30 lightvalue = 5 ldr = gpiozero.LightSensor( ldrpin) #Memanggil class MotionSensor dari Library gpiozero pir = gpiozero.MotionSensor( pirpin) #Memanggil class MotionSensor dari Library gpiozero relay1 = gpiozero.OutputDevice( relaypin, active_high=False, initial_value=False) #set relay sebagai OutputDevice def time_sett(): global times times = simpledialog.askinteger("TIME (s)", "Enter Time (in second)", initialvalue=times, minvalue=4) while times == None: messagebox.showwarning(message='Time tidak boleh kosong')