Back to Parent

int forceSensor = A2;
int vibratingMotor = D4;

int analogvalue;

void setup()
{
  Serial.begin(9600);
  pinMode(vibratingMotor, OUTPUT);
  Mesh.subscribe("vibration2 on", vibrationOnHandler);
  Mesh.subscribe("vibration2 off", vibrationOffHandler);
}

void loop() {
    analogvalue = analogRead(forceSensor);
    if (analogvalue>800) {
       Mesh.publish("vibration1 on", "PRIVATE");
    } else if (analogvalue<=800){
       Mesh.publish("vibration1 off", "PRIVATE");
    }

    Serial.printlnf("%d", analogvalue);
    delay(100);
}

void vibrationOnHandler(const char *event, const char *data)
{
  digitalWrite(vibratingMotor,HIGH);
}

void vibrationOffHandler(const char *event, const char *data)
{
  digitalWrite(vibratingMotor,LOW);
}
Click to Expand

Content Rating

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

0