// This #include statement was automatically added by the Particle IDE.
#include "lib1.h"
// This #include statement was automatically added by the Particle IDE.
#include "Arduino/Arduino.h"
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
unsigned long int duration=0;
int relayPin= 5;
int relayPin2=4;
int buttonState = 64000000;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 115200 bits per second:
Serial.begin(115200);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT_PULLUP);
pinMode(relayPin,OUTPUT);
pinMode(relayPin2,OUTPUT);
digitalWrite(relayPin,LOW);
digitalWrite(relayPin2,HIGH);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
//buttonState =(duration) ;
// print out the state of the button:
duration = pulseIn(pushButton, HIGH);
Serial.println(" RPM ");
//Serial.println(buttonState);
Serial.print(duration);
//i want the pin5 to turn off once my vaule on the serial monitor reads >2000 which pin 2 is the ir-reflectance sensor that is counting:
if ((duration < 25000) && (duration > 0)){
digitalWrite(relayPin2,LOW);
digitalWrite(relayPin,HIGH);
delay(5000);
while(1);
}
//while(1); // delay in between reads for stability
}
Comments