Ir al contenido principal

Radar de velocidad

Las siguientes líneas de código dibujan y actúan como un radar de velocidad en pequeña escala. El sensor lee dos distancias (una inicial y una final) entre 50 y 10 cm, es a los 50 cm cuando lee la inicial y a menos de 10 cuando obtiene la final, al mismo tiempo contara las décimas de segundo para obtener el tiempo. Ya teniendo las dos variables necesarias para calcular una velocidad solo realiza la operación y muestra el resultado en la interfaz. 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

import time
import botbook_gpio as gpio
from turtle import *

t=Turtle()
screen=t.getscreen()
setup(720,720,0,0)
t.speed(5)
t.penup()
screen.bgcolor("gray")
t.fillcolor("white")
t.begin_fill()
t.goto(200,-200)
t.pendown()
t.goto(200,200)
t.goto(-200,200)
t.goto(-200,-200)
t.goto(200,-200)
t.end_fill()
t.fillcolor("lightgray")
t.begin_fill()
t.penup()
t.goto(-180,180)
t.pendown()
t.goto(180,180)
t.goto(180,130)
t.goto(-180,130)
t.goto(-180,180)
t.end_fill()
t.penup()
t.hideturtle()
t.goto(-80,140)
t.write("VELOCIDAD",font=("Arial",20,"bold"))
t.goto(-50,-190)
t.write("CM/S",font=("Arial",30))
t.goto(-160,120)
t.fillcolor("black")
t.begin_fill()
t.pendown()
t.goto(160,120)
t.goto(160,-130)
t.goto(-160,-130)
t.goto(-160,120)
t.end_fill()
t.penup()
t.pencolor("Red")
t.goto(-110,-120)

def readDistanceCm():
triggerPin=22
echoPin=27

v1=(331.5+0.6*20)#m/s

gpio.mode(triggerPin,"out")

gpio.mode(echoPin,"in")
gpio.interruptMode(echoPin,"both")

gpio.write(triggerPin, gpio.LOW)
time.sleep(0.5)

gpio.write(triggerPin,gpio.HIGH)
time.sleep(1/1000.0/1000.0)
gpio.write(triggerPin,gpio.LOW)

t1=gpio.pulseInHigh(echoPin)#s

d=t1*v1
d=d/2
return d*100 #cm

try:
while(True):
v=0
t2=0
d1=readDistanceCm()
if d1<=50:
print("Distancia 1 es %.2f cm"%d1)
time.sleep(0.1)
t2+=0.1
d2=readDistanceCm()
if d2<=10:
print("Distancia 2 es %.2f cm"%d2)
D=d1-d2
v=D/t2
else:
continue
if t==0:
v=0.0
print("{}".format(v))
t.write("%.2f"%v,font=("Arial",80,"bold"))
t.undo()
except KeyboardInterrupt:
screen.exitonclick

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Comentarios

Entradas populares de este blog

Funciones Geometricas

En este programa encontramos múltiples formulas para la obtención de área y volumen de una gran variedad de figuras geométricas. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> import math def cuadrado(): lado=float(input("Dame el valor de lado: ")) cuadrado=[] cuadrado.append(lado) area=cuadrado[0]*cuadrado[0] cuadrado.append(area) print("Lado= {}, Area= {}".format(cuadrado[0],cuadrado[1])) def triangulo(): triangulo=[] base=float(input("Dame la base: ")) altura=float(input("Dame la altura: ")) triangulo.append(base) triangulo.append(altura) area=(triangulo[0]*triangulo[1])/2 triangulo.append(area) print("Base= {}, Altura= {}, Area= {}".format(triangulo[0],triangulo[1],triangulo[2])) def rectangulo(): rectangulo...

Fotoresistencia y foco

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> from turtle import * import turtle  import numpy as np from pylab import* import random import time import RPi.GPIO as GPIO, time t=Turtle() screen=t.getscreen() setup(400,300,0,0) screensize(150,150) colormode(255) t=Turtle() t.speed(10) screen=t.getscreen() setup(900,620,0,0) screensize(500,150) colormode(255) turtle.bgcolor("darkgray") t.hideturtle() t.penup() t.pensize(5) t.goto(-250,-150) t.pendown() t.goto(450,-150) t.penup() t.goto(-250,-150) t.pendown() t.goto(-450,-300) t.penup() t.goto(-250,-150) t.pendown() t.goto(-250,500) t.penup() t.goto(100,300) t.pendown() t.dot(40,255,255,255) t.dot(40,255,250,0) t.bgcolor("darkgray") GPIO.setmode(GPIO.BCM) valor=0 def medida (): measu...