Foto resistencia Actualizada en Software


Foto resistencia Actualizada en Software 





#Librerias
from turtle import* 
import turtle
from time import sleep
import RPi.GPIO as GPIO
import time

bg = "pics/room.gif"

GPIO.setmode(GPIO.BOARD)

#turtle Setup
t = Turtle()
turtle.setup(960,574)
screen = t.getscreen()
screen.title("Semaforo Sincronizado")
screen.bgpic(bg) #Fondo de la ventana

colors = ["FFFFEF","FEFFCB","FCFF7D","FAFF4E","F7FF17"]

t.speed(0)
t.penup()
t.ht()

#define the pin that goes to the circuit
pin_to_circuit = 7

def rc_time (pin_to_circuit):
    count = 0
  
    #Output on the pin for 
    GPIO.setup(pin_to_circuit, GPIO.OUT)
    GPIO.output(pin_to_circuit, GPIO.LOW)
    time.sleep(0.1)

    #Change the pin back to input
    GPIO.setup(pin_to_circuit, GPIO.IN)
  
    #Count until the pin goes high
    while (GPIO.input(pin_to_circuit) == GPIO.LOW):
        count += 1

    return count

#Catch when script is interrupted, cleanup correctly
def getResVal():
try:
while True:
data = rc_time(pin_to_circuit)
ResValCalculator(data)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()



def ResValCalculator(val):
if val >= 578 and val < 2574:
Drawbulb(colors[4])
elif val >= 2574 and val < 4570:
DrawBulb(colors[3])
elif val >= 4570 and val < 6566: 
DrawBulb(colors[2])
elif val >= 6566 and val < 8561:
DrawBulb(colors[1])
elif val >= 8562 and val < 10562:
DrawBulb(colors[0])

def DrawBulb(color):
t.forward(47)
t.left(90)
t.forward(144)
t.color("#"+color)
t.begin_fill()
t.circle(40,-180)
t.end_fill()
t.home()
print(color)

def main():
getResVal()

main()

screen.exitonclick()

Comentarios

Entradas populares de este blog

Radar de Detección

From Zero To Hero By Perian Data

Semáforo sincronizado con LEDs en Raspberry PI