Gavin TrotterDaniel Law
Published

Lane Tech HS - PCL - Mario Pipe(Prototype)

Its a me, Gavin! and I used a particle Argon to move Mario up and down a pole dependent on the Stock price on Nintendo. #FreeMelle

IntermediateFull instructions provided179
Lane Tech HS - PCL - Mario Pipe(Prototype)

Things used in this project

Hardware components

PVC Pipe
×1
Argon
Particle Argon
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Through-Bolt, 2.75" Length
Through-Bolt, 2.75" Length
×1
Connector Accessory, Hex Nut
Connector Accessory, Hex Nut
×2
Pulley
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Rapid API Yahoo Finace

Hand tools and fabrication machines

Scissors, Free Fall
Scissors, Free Fall
Tape, Duct
Tape, Duct
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Servo Schematic

Code

Source Code

C/C++
This is the code used to connect all the dots(API to the Webhook To the Particle to the Servo)
// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>

// The number below has to be updated to the correct doc size
// Use the official ArduinoJSON Assistant below:
// https://arduinojson.org/v6/assistant/
StaticJsonDocument<200> doc;

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position
float currentPrice=0; // variable to store the the current price
float oldPrice = 0; ; // variable to store the the past price

void setup()
{
    myservo.attach(D8);  // attaches the servo on the D0 pin to the servo object
    // Subscribe to the webhook response event
    Particle.subscribe("hook-response/StockPrice", myHandler, MY_DEVICES);
    Serial.begin(9600);
}

void loop()
{
  String data = String(10);// Get some data
  Particle.publish("StockPrice", data, PRIVATE); // Trigger integration
  delay(60000);// Wait 60 seconds
}

void myHandler(const char *event, const char *data)
{
    float price =atof(data);//ask the API for the price of NTDOY

    float oldPrice = currentPrice;//when the price changes changes, old price becomes the new price 
    float currentPrice = price;//the value pulled by the API becomes currentPrice
    
    if(currentPrice > oldPrice)
    {
       int pos = (currentPrice - oldPrice) * 10;//sets position of the servo 
        myservo.write(pos);// moves servo and moves Mario up
        delay(200);
    }
  
   if(currentPrice < oldPrice)
    {
       int pos = (oldPrice - currentPrice) * -10;;//sets position of the servo 
        myservo.write(pos);// moves servo and moves Mario down
        delay(200);
    }
}

Credits

Gavin Trotter
3 projects • 2 followers
Contact
Daniel Law
46 projects • 9 followers
Teacher. Maker. Citizen of the planet.
Contact

Comments

Please log in or sign up to comment.