// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_PWMServoDriver.h>
// This #include statement was automatically added by the Particle IDE.
#include <Stepper.h>
const int stepsPerRevolution = 2048;
// Any digital pins should work. Change as necessary.
#define IN1 3
#define IN2 4
#define IN3 5
#define IN4 6
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper(stepsPerRevolution, IN1, IN3 , IN2, IN4);
#include "Particle.h"
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
#if (PLATFORM_ID == 32)
// MOSI pin MO
#define PIXEL_PIN SPI1
// MOSI pin D2
// #define PIXEL_PIN SPI1
#else // #if (PLATFORM_ID == 32)
#define PIXEL_PIN D2
#endif
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812B
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// setup() runs once, when the device is first turned on
JsonDocument doc;
String p1em=" ";
String p1jm=" ";
String p2em=" ";
String p2jm=" ";
String p3em=" ";
String p3jm=" ";
String p4em=" ";
String p4jm=" ";
String p5em=" ";
String p5jm=" ";
String p6em=" ";
String p6jm=" ";
String p7em=" ";
String p7jm=" ";
String p8em=" ";
String p8jm=" ";
int x = 1;
int servonum= -1;
int r = random(8);
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150
#define SERVOMAX 600
void setup() {
// Put initialization like pinMode and begin functions here
Serial.begin(9600);
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
while(Particle.disconnected()){
delay (100);
Serial.println("...Particle is trying to connect to the cloud...");
}
Serial.println("Particle connected 2 cloud");
Particle.subscribe("hook-response/planets", mvh);
Particle.publish("planets");
strip.begin();
strip.show();
pwm.begin();
pwm.setPWMFreq(60);
myStepper.setSpeed(15);
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
Serial.println("clockwise");
myStepper.step(500);
delay(500);
yTho(r);
strip.show();
delay(500);
pwm.setPWM(servonum, 0, 390);
Serial.println("390");
delay(500);
pwm.setPWM(servonum, 0, 160);
Serial.println("160");
delay(500);
Serial.println("counterclockwise");
myStepper.step(-500);
delay(500);
}
void mvh(const char *event, const char *data)
{
Serial.println("mvh is starting...");
int numChars = 2000;
char strBuffer[numChars];
strcpy(strBuffer, data);
String date1 = strtok(strBuffer, "|");
p1em = strtok(NULL, "|");
p1jm = strtok(NULL, "|");
String date2 = strtok(NULL, "|");
p2em = strtok(NULL, "|");
p2jm = strtok(NULL, "|");
String date3 = strtok(NULL, "|");
p3em = strtok(NULL, "|");
p3jm = strtok(NULL, "|");
String date4 = strtok(NULL, "|");
p4em = strtok(NULL, "|");
p4jm = strtok(NULL, "|");
String date5 = strtok(NULL, "|");
p5em = strtok(NULL, "|");
p5jm = strtok(NULL, "|");
String date6 = strtok(NULL, "|");
p6em = strtok(NULL, "|");
p6jm = strtok(NULL, "|");
String date7 = strtok(NULL, "|");
p7em = strtok(NULL, "|");
p7jm = strtok(NULL, "|");
String date8 = strtok(NULL, "|");
p8em = strtok(NULL, "|");
p8jm = strtok(NULL, "|");
Serial.println(" begin planet 1:-- earth radius = "+ p1em+ " jupiter radius = "+ p1jm + "--: end planet 1");
Serial.println(" begin planet 2:-- earth radius = "+ p2em+ " jupiter radius = "+ p2jm + "--: end planet 2");
Serial.println(" begin planet 3:-- earth radius = "+ p3em+ " jupiter radius = "+ p3jm + "--: end planet 3");
Serial.println(" begin planet 4:-- earth radius = "+ p4em+ " jupiter radius = "+ p4jm + "--: end planet 4");
Serial.println(" begin planet 5:-- earth radius = "+ p5em+ " jupiter radius = "+ p5jm + "--: end planet 5");
Serial.println(" begin planet 6:-- earth radius = "+ p6em+ " jupiter radius = "+ p6jm + "--: end planet 6");
Serial.println(" begin planet 7:-- earth radius = "+ p7em+ " jupiter radius = "+ p7jm + "--: end planet 7");
Serial.println(" begin planet 8:-- earth radius = "+ p8em+ " jupiter radius = "+ p8jm + "--: end planet 8");
Serial.println("mvh is ending...");
//https://build.particle.io/build/698a2a015a06b5000972ee5d#flash}
}
void lights(String eR,String jR){
// blue is small earth, cyan is earth, green is large earth
// yellow is small jupter, orange is jupiter, red is large jupiter
double earthRad = eR.toFloat();
double jupiterhRad = jR.toFloat();
if (earthRad<0.75 && earthRad != 0){ // cheching if mini earth
for (int i=0; i<8; i++){
strip.setPixelColor(i, 0, 0, 255);
strip.show();
}
servonum = 0;
return;
}
if (earthRad>=0.75 && earthRad<1.25){ // checking if earth mass
for (int i=0; i<8; i++){
strip.setPixelColor(i, 0, 204, 102);
strip.show();
}
servonum = 2;
return;
}
if (earthRad>=1.25 && earthRad<2.25){ // checking if likely super earth
for (int i=0; i<8; i++){
strip.setPixelColor(i, 0, 255, 0);
strip.show();
}
servonum = 4;
return;
}
if (earthRad>=2.25 && jupiterhRad<0.34){ // cheching if likely mini gas planet
for (int i=0; i<8; i++){
strip.setPixelColor(i, 255, 255, 0);
strip.show();
}
servonum = 7;
return;
}
if (jupiterhRad>=0.34 && jupiterhRad<1.5){ // cheching if jup sized gas planet
for (int i=0; i<8; i++){
strip.setPixelColor(i, 255, 75, 0);
strip.show();
}
servonum = 8;
return;
}
if (jupiterhRad>=1.25 && jupiterhRad<2){ // cheching if likley star
for (int i=0; i<8; i++){
strip.setPixelColor(i, 255, 0, 0);
strip.show();
}
servonum = 10;
return;
}
if (earthRad == NULL || earthRad == 0){ // cheching if null
for (int i=0; i<8; i++){
strip.setPixelColor(i, 255, 255, 255);
strip.show();
}
return;
}
}
void yTho (int n){
if (n==0){
lights (p1em, p1jm);
strip.show();
}
if (n==1){
lights (p2em, p2jm);
strip.show();
}
if (n==2){
lights (p3em, p3jm);
strip.show();
}
if (n==3){
lights (p4em, p4jm);
strip.show();
}
if (n==4){
lights (p5em, p5jm);
strip.show();
}
if (n==5){
lights (p6em, p6jm);
strip.show();
}
if (n==6){
lights (p7em, p7jm);
strip.show();
}
if (n==7){
lights (p8em, p8jm);
strip.show();
}
}
Comments