Back to Parent

// Skill Dev #5: Working with Networking

// Servo
Servo servo;
int servoPin = A3;

// Switch button
int pushBtn = D3;

int minutes = 0;

void setup() {
    Serial.begin(9600);

    // Setup servo
    servo.attach(servoPin);
    servo.write(0);
    delay(500);
    servo.write(180);
    delay(500);

    pinMode(pushBtn, INPUT_PULLUP);

    Particle.function("setTime", setTime);
    
    Particle.subscribe("blinkLED", handleRemoteEvent);
}

void loop() {

    int switchState = digitalRead(pushBtn);

    if (switchState == LOW) {
   
        Particle.publish("doPairedPublish");
    }
}

int setTime(String cmd) {
    minutes = cmd.toInt();
    return minutes;
}

void handleRemoteEvent(const char *event, const char *data) {
   
    int position = String(data).toInt();
    servo.write(position);
}
Click to Expand

Content Rating

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

0