tutRPi / Raspberry-Pi-Heartbeat-Pulse-Sensor

34 stars 42 forks source link

using tkinter animation with example py #2

Open tinaburton opened 6 years ago

tinaburton commented 6 years ago

Hello; I am using your code in the hope of attaching an animation to correspond with the heart rate. However it doesn't work and I am totally new to python coding. could you help? here is the code I have included in your example.py from pulsesensor import Pulsesensor import time from tkinter import * import random

tk = Tk() WIDTH=1500 HEIGHT=800 canvas = Canvas(tk, bg="brown4", height=HEIGHT, width= WIDTH) tk.title("drawing") canvas.pack()

below is the class to create multiple balls that are coloured

and move and detect the edge and bounce

class Ball: def init(self, color, size):
self.shape = canvas.create_oval (10, 10, size, size, fill=color, outline=color, stipple="gray25") self.xspeed =random.randrange(-1,5) self.yspeed =random.randrange (-1,5) def move(self): canvas.move(self.shape, self.xspeed, self.yspeed) pos = canvas.coords(self.shape) if pos[3]>=HEIGHT or pos[1]<=0: self.yspeed=-self.yspeed if pos[2] >=WIDTH or pos[0] <=0:
self.xspeed=-self.xspeed

colors=["red4", "red3", "OrangeRed2","OrangeRed4","firebrick3"]

this is make 100 balls

balls=[] for i in range (100):

this is to set the colour and size of the balls which is randomised, so they can

            balls.append(Ball(random.choice(colors), random.randrange(150, 200)))

this is to call the balls

while True:

p = Pulsesensor() p.startAsyncBPM()

try: while True: bpm = p.BPM if bpm > 0: print("BPM: %d" % bpm) for ball in balls: ball.move() tk.update() time.sleep(0.02) tk.mainloop() else: print("No Heartbeat found") time.sleep(1) except: p.stopAsyncBPM()

jchenaud commented 6 years ago

i want to make somthing like you do you have find solution ?

tinaburton commented 6 years ago

Hiya; I have not had time to work on it very much. The main problem was in stabilising the signal from the heart rate monitor. I have been advised to put it inside of a dark holder (like a thimble or something similar). Hope this helps. Tina

From: jchenaud notifications@github.com Reply-To: tutRPi/Raspberry-Pi-Heartbeat-Pulse-Sensor reply@reply.github.com Date: Thursday, 2 August 2018 at 09:02 To: tutRPi/Raspberry-Pi-Heartbeat-Pulse-Sensor Raspberry-Pi-Heartbeat-Pulse-Sensor@noreply.github.com Cc: "Burton, Tina" tina.burton@anglia.ac.uk, Author author@noreply.github.com Subject: Re: [tutRPi/Raspberry-Pi-Heartbeat-Pulse-Sensor] using tkinter animation with example py (#2)

i want to make somthing like you do you have find solution ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/tutRPi/Raspberry-Pi-Heartbeat-Pulse-Sensor/issues/2#issuecomment-409841704, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfH9J6jV3uXXd9roCjiog7dqoBTOh8E_ks5uMrITgaJpZM4PyP7j.

--

TAKE CARE: this message originates from an email service outside of our University. Do not click on any links or open attachments unless you recognise the sender and are absolutely sure that the content is safe

-- Please click here to view our e-mail disclaimer http://www.anglia.ac.uk/email-disclaimer