int forceSensor = A2;
int vibratingMotor = D11;
int analogvalue;
void setup()
{
Serial.begin(9600);
pinMode(vibratingMotor, OUTPUT);
Mesh.subscribe("vibration1 on", vibrationOnHandler);
Mesh.subscribe("vibration1 off", vibrationOffHandler);
}
void loop() {
analogvalue = analogRead(forceSensor);
if (analogvalue>800) {
Mesh.publish("vibration2 on", PRIVATE);
} else if (analogvalue<=800){
Mesh.publish("vibration2 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!
You must login before you can post a comment. .