foco con fotoresitencia

en este programa veremos como usar los puertos de la raspberry para le lactura de datos asi como para general una señal, en concreto mediante un pequeño circuito con una fotoresistencias pondremos en pantalla los cambios de luz que presencia la fotoresitencia






from turtle import*
import RPi.GPIO as GPIO, time
t=Turtle()
screen=t.getscreen()
setup(600,600,0,0)
screensize(600,600)
colormode(255)
t.speed(0)
t.penup()
t.goto(-125,-30)
t.pendown()
t.fillcolor("gray")
t.begin_fill()
t.goto(-125,-70)
t.goto(-75,-70)
t.goto(-75,-30)
t.goto(-125,-30)
t.end_fill()

t.penup()
t.goto(-125,-70)
t.pendown()
t.left(-90)
t.circle(25,180)

t.penup()
t.goto (-100,20)
t.dot(120,255,255,0)
GPIO.setmode(GPIO.BCM)
measurement=0
val=0
t.hideturtle()

def datos():
measurement=0
while (GPIO.input(4) == GPIO.LOW):

measurement += 1
print(measurement)
return measurement


while True:

GPIO.setup(4, GPIO.OUT)
GPIO.output(4, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(4, GPIO.IN)

val=datos()
print(val)


if (val<100)and(val>-100):
t.dot(120,255,255,0)
elif(val<200)and(val>100):
t.dot(120,252,252,0)
elif(val<300)and(val>200):
t.dot(120,226,226,0)
elif((val<400)and(val>300)):
t.dot(120,201,201,0)
elif(val<500)and(val>400):
t.dot(120,175,175,0)
elif(val<600)and(val>500):
t.dot(120,150,150,0)
elif(val<700)and(val>600):
t.dot(120,124,124,0)
elif(val<800)and(val>700):
t.dot(120,99,99,0)
elif(val<900)and(val>800):
t.dot(120,73,73,0)
elif(val<1000)and(val>900):
t.dot(120,48,48,0)
else:
t.dot(120,40,40,0)






exitonclick()

Comentarios

Entradas populares de este blog

formulas para calcular area y volumes de algunos cuerpos en python

matrices en python

como imprimir figuras en python