Back to Parent

//---------------------------------------------------//
//     This code is for Blackcat with Motor_Fan      //
//---------------------------------------------------//
// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int motorPin = D3;

bool shouldActivate = false;
String WHITE_CAT = "e00fce68451e0478b4367278";
void setup() {
    Particle.function( "activateMotor", activateMotor );
    Particle.subscribe("diot/2019/hannah/reach10/" + WHITE_CAT, setLevelLow);
    Particle.subscribe("diot/2019/hannah/reach20/" + WHITE_CAT, setLevelMid);
    Particle.subscribe("diot/2019/hannah/reach30/" + WHITE_CAT, setLevelHigh);
    Particle.subscribe("diot/2019/hannah/resetMotor/" + WHITE_CAT, resetMotor);
    pinMode(motorPin, OUTPUT);
    analogWrite(motorPin, 0);
}

void loop() {

}

void setMotorLevel(int level){
    analogWrite(motorPin, level);
}

void setLevelLow(const char *event, const char *data) {
    activateMotor("low");
}
void setLevelMid(const char *event, const char *data) {
    activateMotor("mid");
}
void setLevelHigh(const char *event, const char *data) {
    activateMotor("high");
}
void resetMotor(const char *event, const char *data) {
    activateMotor("");
}

int activateMotor( String command ){
    if (command == "high") {
        setMotorLevel(255);
    } else if (command == "mid") {
        setMotorLevel(200);
    } else if (command == "low") {
        setMotorLevel(150);
    } else {
        setMotorLevel(0);
    }
  return 1;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0