Sebastian Felix Schwarz
Published © MIT

Covid-19 stats Germany

A Device showing up the current Stats of Infections and dead People by Covid-19.

IntermediateFull instructions provided1 hour250
Covid-19 stats Germany

Things used in this project

Hardware components

Argon
Particle Argon
you can use any other WLAN Device
×1
8 Digit - 7 segment
×2
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1

Software apps and online services

AWS Lambda
Amazon Web Services AWS Lambda
to get the Data from RKI
AWS API Gateway
Amazon Web Services AWS API Gateway
to trigger a Lambda
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Code

Covid-19 Stats

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <LedControl-MAX7219-MAX7221.h>

// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>
 
Timer cointimer(3600000, cointimerfunction);
DynamicJsonDocument doc(1024);

LedControl lc=LedControl(12,1,0,1);

LedControl lc1=LedControl(11,3,2,1);
unsigned long delaytime=250;

int i = 0;

int ledRed = D5;
int ledGreen = D6;



unsigned int pow [] = { 1, 10, 100, 1000, 10000, 100000, 1000000 } ;

int ExtractDigit(int V, int P)
{
  return V / pow[P] % 10 ;
}


void myHandler(const char *event, const char *data)
{
  Serial.print(event);
  Serial.print(", data: ");
  Serial.println(data);
  if (data){
    auto error = deserializeJson(doc, data);
    if (error) {
      Serial.print(F("deserializeJson() failed with code "));
      Serial.println(error.c_str());
      return;
    }
    int infizierte = doc["infizierte"];
    int tote = doc["tote"];
    int status = doc["status"];
    Serial.println("Data loaded:");
    Serial.println(infizierte);
    Serial.println(tote);
    Serial.println(status);
    
    if(status > 0){
      
    digitalWrite(ledGreen, LOW);
  digitalWrite(ledRed, HIGH);
  }else{
      
    digitalWrite(ledGreen, HIGH);
    digitalWrite(ledRed, LOW);
  }
  
  displayNumber1(infizierte);
  
  displayNumber2(tote);
  
  }else{
    Serial.println("NULL");
  }
  
}

void displayNumber1(int n){
    lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
    if(n>999999){
        lc.setChar(0,6,ExtractDigit(n,6),true);
    }
    if (n>99999){
        lc.setChar(0,5,ExtractDigit(n,5),false);
    }
    if (n>9999){
        lc.setChar(0,4,ExtractDigit(n,4),false);
    }
    if (n>999){
        lc.setChar(0,3,ExtractDigit(n,3),true);
    }
    if (n>99){
        lc.setChar(0,2,ExtractDigit(n,2),false);
    }
    if (n>9){
        lc.setChar(0,1,ExtractDigit(n,1),false);
    }
    if (n>0){
        lc.setChar(0,0,ExtractDigit(n,0),false);
    }
    
}
void displayNumber2(int n){
    lc1.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc1.setIntensity(0,8);
  /* and clear the display */
  lc1.clearDisplay(0);
    if(n>999999){
        lc1.setChar(0,6,ExtractDigit(n,6),true);
    }
    if (n>99999){
        lc1.setChar(0,5,ExtractDigit(n,5),false);
    }
    if (n>9999){
        lc1.setChar(0,4,ExtractDigit(n,4),false);
    }
    if (n>999){
        lc1.setChar(0,3,ExtractDigit(n,3),true);
    }
    if (n>99){
        lc1.setChar(0,2,ExtractDigit(n,2),false);
    }
    if (n>9){
        lc1.setChar(0,1,ExtractDigit(n,1),false);
    }
    if (n>0){
        lc1.setChar(0,0,ExtractDigit(n,0),false);
    }
    
}

void cointimerfunction(){
    System.reset();
}

void setup() {
    pinMode(ledRed, OUTPUT);
    pinMode(ledGreen, OUTPUT);
 Serial.println("Setup");
    
  // Subscribe to the integration response event
  lc1.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc1.setIntensity(0,8);
  /* and clear the display */
  lc1.clearDisplay(0);
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
  
  digitalWrite(ledRed, HIGH);
    digitalWrite(ledGreen, HIGH);
  
  Particle.subscribe("hook-response/getCovidData", myHandler, MY_DEVICES);
  bool success = Particle.publish("getCovidData"); // Trigger Webhook
  delay(delaytime);
  
  lc1.clearDisplay(0);
  lc.clearDisplay(0);
  digitalWrite(ledRed, LOW);
    digitalWrite(ledGreen, LOW);
    
  cointimer.start();
  
}

void loop() {
    delay(250);
  // not used in this example
}

Credits

Sebastian Felix Schwarz

Sebastian Felix Schwarz

1 project • 0 followers

Comments