Data Responsive Project

by jebazzell in Circuits > Arduino

46 Views, 0 Favorites, 0 Comments

Data Responsive Project

pclgooo-ezgif.com-video-to-gif-converter.gif

This project spins a continuous servo motor and lights two LED matrices in response to real-time data. The data is pulled from the National Institute of Standards and Technology CVE database, which tracks security breaches and vulnerabilities in software used worldwide.

Every five minutes, the program checks for an update to the database, at which point the motor spins, and the two matrices change their displays. One matrix displays an "evil" face to represent the hacker, and the other displays an "X," to represent the computer crashing.


Sorry the video is bad! Instructables won't let me upload a different one. Let me know if you need another one! :)

Supplies

  • Laptop
  • Particle Argon
  • Breadboard
  • 2 LED Matrices
  • Continuous Servo Motor
  • Jumper Wires

Code

// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>


// This #include statement was automatically added by the Particle IDE.
#include <ledmatrix-max7219-max7221.h>


JsonDocument doc;


LEDMatrix *led1;
LEDMatrix *led2;
Servo myServo;


int numArts;
int lastRun;
String dates;


String year;
String month;
String day;
String hour;
String minute;


void setup() {
    myServo.attach(2);
    
    //CLK = A0, CS = A1, DI = A2
    led1 = new LEDMatrix(1, 1, A0, A1, A2);
    // CLK = A3, CS = A4, DI = A5
    led2 = new LEDMatrix(1, 1, A3, A4, A5);
    led1->addMatrix(0, 0, 270);
    led2->addMatrix(0, 0, 270);
    flush();
    
    Time.zone(-5);
    makeDate();
    lastRun = millis();
    Particle.publish("notVuls", dates);
    Particle.subscribe("hook-response/notVuls/0", myHandler);
    Serial.begin(9000);
    delay(5000);
}


void loop(){
    if ((millis() - lastRun) > 300000)
    {
        makeDate();
        Particle.publish("notVuls", dates);
        delay(5000);
        if(numArts > 0)
        {
            myServo.write(50);
            
            led1->drawLine(0, 0, 7, 7, true); //draws an X on led1
            led1->drawLine(0, 7, 7, 0, true);
            
            led2->drawLine(2, 0, 3, 1, true); //draws an evil face on led2
            led2->drawLine(5, 1, 6, 0, true);
            led2->drawLine(2, 3, 2, 4, true);
            led2->drawLine(6, 3, 6, 4, true);
            led2->drawLine(1, 6, 2, 7, true);
            led2->drawLine(3, 7, 4, 7, true);
            led2->drawLine(5, 7, 7, 6, true);
            
            flush();
            
            delay(8000);
            
            led1->fillScreen(false); //clears screens
            led2->fillScreen(false);
            
            flush();
            
            myServo.writeMicroseconds(1500); //stops servo
        }
        lastRun = millis();
    }
}


void makeDate()
{
    year = (String)Time.year();
    month = (String)Time.month();
    if (Time.month() < 10)
    {
        month = ("0" + month); //formats the date components to have a leading zero, as needed for the api call
    }
    day = (String)Time.day();
    if (Time.day() < 10)
    {
        day = ("0" + day);
    }
    hour = (String)Time.hour();
    if (Time.hour() < 10)
    {
        hour = ("0" + hour);
    }
    minute = (String)Time.minute();
    if (Time.minute() < 10)
    {
        minute = ("0" + minute);
    }
    if(Time.minute() > 14)
    {
        dates = "{\"pubStartDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":" + (String)(Time.minute() - 5) + ":00.000\",\"pubEndDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":00.000\"}";
    }
    else if(Time.minute() > 5)
    {
        dates = "{\"pubStartDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":0" + (String)(Time.minute() - 5) + ":00.000\",\"pubEndDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":00.000\"}";
    }
    else if (Time.minute() < 5 && Time.hour() != 00 && Time.hour() > 10)
    {
        dates = "{\"pubStartDate\":\"" + year + "-" + month + "-" + day + "T" + (String)(Time.hour() - 1) + ":0" + (String)(60 - Time.minute()) + ":00.000\",\"pubEndDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":00.000\"}";
    }
    else if (Time.hour() < 11 && Time.hour() > 0)
    {
        dates = "{\"pubStartDate\":\"" + year + "-" + month + "-" + day + "T0" + (String)(Time.hour() - 1) + ":" + (String)(60 - Time.minute()) + ":00.000\",\"pubEndDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":00.000\"}";
    }
    else if (Time.hour() > 0 && Time.minute() < 5)
    {
        dates = "{\"pubStartDate\":\"" + year + "-" + month + "-" + day + "T0" + (String)(Time.hour() - 1) + ":0" + (String)(60 - Time.minute()) + ":00.000\",\"pubEndDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":00.000\"}";
    }
    else if (Time.hour() == 0)
    {
        dates = "{\"pubStartDate\":\"" + year + "-" + month + "-" + day + "T23:" + (String)(60 - Time.minute()) + ":00.000\",\"pubEndDate\":\"" + year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":00.000\"}";
    }
    Serial.println(dates);


}


void flush()
{
    led1->flush();
    led2->flush();
}


void myHandler(const char* event, const char* data) {
    Serial.println("PUBKSIHGING");
    const char* json = data;


    deserializeJson(doc, json);
    
    Serial.println(json);
    
    // JsonObject main = doc["main"]; // Not really needed
    numArts = doc["totalResults"];
    
    Serial.println("numarts:");
    Serial.println(numArts);
    
}