COVID-19 Tracker

Copyright Claim

COVID-19 Tracker

Boost
0
0
0

Print Profile(0)


Add the first print profile to earn points

Boost
0
0
0
0
0
0
Released

Description

Summary

COVID-19 Tracker for At-a-glance : https://youtu.be/viHVAZqpwsI

C - Cases
R - Recovered
D - Deaths

Holes are intended for standard 5mm LEDs, and should fit snug with proper tolerance. If not, a quick blast with a lighter on the standoffs should allow the LED to fit in.

Rough example of code that runs the flashingLEDs:

import requests
import json
import RPi.GPIO as GPIO
from time import sleep
import threading

CURRENT_DATA = dict()
ACTIVE_PINS = {"cases": 22, "recovered": 18, "deaths": 17}
CHANGE_INDICATOR_ENABLE = False
DATA_API_URL = "https://coronavirus-19-api.herokuapp.com/all"

def get_data():
   """
   THis method should obtain from a reputable source the current data for COVID-19
   The Return should be a JSON payload in the format of {"cases":n, "recovered":n, "deaths":n}
   Should this not match, the above reference GPIO in ACTIVE_PINS should be adjusted. This matches for the
   indicator lites based on the GPIO pin for each led.
   :return: n/a - starts a thread to blink the GPIO pins.
   """
   response = json.loads(requests.get(DATA_API_URL).text)
   print(response)
   if CURRENT_DATA != response:
       for key, value in response.items():
           if key not in CURRENT_DATA.keys():
               CURRENT_DATA[key] = value
               print('value was not found for %s, now added' % key)
           else:
               if response[key] != CURRENT_DATA[key]:
                   print("%s is not matching" % key)
                   threading.Thread(name=key, target=record_new_numbers, args=(key, value)).start()

def record_new_numbers(key, value):
   increment_number = 0
   print('adding %s, have %s need %s' % (key, CURRENT_DATA[key], value))
   while CURRENT_DATA[key] < value:

       CURRENT_DATA[key] += 1
       increment_number += 1
   blink_n_times(ACTIVE_PINS[key], increment_number)

def blink_n_times(gpio_number, blink_times):
   already_blunk = 0
   # Long enable to indicate this is a new number increment.
   blink_gpio(gpio_number, delay=3) if CHANGE_INDICATOR_ENABLE else None
   while blink_times > already_blunk:
       already_blunk += 1
       blink_gpio(gpio_number)

def blink_gpio(number, delay=0.1, secondary_delay=0.1):
   GPIO.output(number, GPIO.HIGH)
   sleep(delay)
   GPIO.output(number, GPIO.LOW)
   sleep(secondary_delay)

def setup_gpio():
   GPIO.setmode(GPIO.BCM)
   for k, v in ACTIVE_PINS.items():
       GPIO.setup(v, GPIO.OUT)
       GPIO.output(v, GPIO.HIGH)
       sleep(0.4)
       GPIO.output(v, GPIO.LOW)
       print("setup pin %s for %s" % (v, k))

if __name__ == '__main__':
   setup_gpio()
   print('Setup of GPIO pins complete')

   try:
       while True:
           get_data()
           sleep(30)
   except KeyboardInterrupt:
       GPIO.cleanup()

Comment & Rating (0)

Please fill in your opinion
(0/5000)

No more