@modsbyus wrote:
I used the blink without delay example to help me write this. The idea is that I would click the widget in the dashboard on then off and let the code turn the pin off after a period of time. I have my variable "oneHour" currently set to 5000. When I turn on my widget in the dashboard, the pin goes high then almost immediately goes low. I think I'm close but....
CAYENNE_IN(VIRTUAL_PIN3) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 unsigned long currentMillis = millis(); unsigned long previousMillis = 0; // read the state of the switch into a local variable: reading = digitalRead(buttonPin); buttonState = reading; Serial.print("buttonState "); Serial.print(buttonState); // assuming you wire your relay as normally open if (currentValue == 1 || buttonState == 1) { Serial.println("1st if"); digitalWrite(ledPin, HIGH); digitalWrite(relayPin, HIGH); count++; if (currentMillis - previousMillis >= oneHour){ previousMillis = currentMillis; Serial.println("2nd if"); if (count > preCount){ Serial.println("3rd if"); digitalWrite(ledPin, LOW); digitalWrite(relayPin, LOW); buttonState = 0; preCount = count; } } } }
Posts: 1
Participants: 1