Back to Parent

int pressuresensor = A0;

int pos = 0;

//int vibration = 5;

Servo rotation; // create servo object to control a servo

// a maximum of eight servo objects can be created

int led = 3;

//Servo rotation;

//int temp = millis()

int state = 0;

int counter = 0;

void setup()

{

pinMode(pressuresensor, INPUT);

// pinMode(vibration, OUTPUT);

pinMode(led, OUTPUT);

//rotation.attach(D0);

// can be called from the cloud

// connect it to the gong function below

rotation.attach(A0); // attach the servo on the D0 pin to the servo object

rotation.write(25); // test the servo by moving it to 25°

pinMode(D3, OUTPUT); // set D7 as an output so we can flash the onboard LED

}

void loop()

{

int pressure2 = analogRead(pressuresensor);

// if (pressure2>100) {

// //counter=counter+1;

// int start = temp;

// }

// else

// {

// counter = 0;

// }

if (state != 1)

{

while (pressure2>100)

{

counter = counter+1;

// Particle.publish("time",String(count));

delay(1000);

if (counter>6)

{

rotation.write(0); // move servo to 0° - ding!

digitalWrite(D2, HIGH); // flash the LED (as an indicator) digitalWrite(vibration, HIGH);

digitalWrite(led, HIGH);

state = 1;

return;

}

}

}

if (pressure2<100)

{

rotation.write(25); // move servo to 25°

digitalWrite(D2, LOW); // turn off LED

// digitalWrite(vibration, LOW);

digitalWrite(led, LOW);

counter = 0;

state = 0;

Particle.publish("pressuresensor",String(pressure2));

}

// if (counter>5) {

// digitalWrite(vibration, HIGH);

// } else {

// digitalWrite(vibration, LOW);

// }

// Particle.publish("time",String(count));


}
Click to Expand

Content Rating

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

0