int sensorPin = D3;
int ledPin = D2;
void setup() {
pinMode(ledPin, OUTPUT);
Particle.subscribe("blinkLED", handleActivateLED);
blinkLED(3, ledPin);
}
unsigned long readQTR() {
unsigned long duration = 0;
pinMode(sensorPin, OUTPUT);
digitalWrite(sensorPin, HIGH);
delayMicroseconds(10);
pinMode(sensorPin, INPUT);
while(digitalRead(sensorPin) == HIGH) {
duration++;
if(duration > 3000) break;
}
return duration;
}
void loop() {
unsigned long sensorValue = readQTR();
if(sensorValue < 3000) {
digitalWrite(ledPin, HIGH);
Particle.publish("doPairedPublish");
} else {
digitalWrite(ledPin, LOW);
}
delay(100);
if(doBlink) {
blinkLED(6, ledPin);
doBlink = false;
}
}
void blinkLED( int times, int pin ){
for( int i = 0; i < times ; i++ ){
digitalWrite( pin, HIGH );
delay( 500 );
digitalWrite( pin, LOW );
delay( 500 );
}
}
void handleActivateLED( const char *event, const char *data)
{
doBlink = true;
}
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. .