Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sendLedPin = D7;
- int inputPin = D4;
- int receiveLedPin = D0;
- int receiveLedPin2 = D6;
- int lastVal = 0;
- int sendLedVal = 0;
- void ledTwoToggle(const char *toggle, const char *onOff); //handler function for Spark.subscribe()
- void setup()
- {
- pinMode(receiveLedPin, OUTPUT);
- pinMode(receiveLedPin2, OUTPUT);
- pinMode(sendLedPin, OUTPUT);
- pinMode(inputPin, INPUT_PULLUP);
- digitalWrite(sendLedPin, LOW);
- digitalWrite(receiveLedPin, LOW);
- digitalWrite(receiveLedPin2, LOW);
- Spark.publish("Core1Toggle", "State", 0);
- Spark.subscribe("Core2Toggle", ledTwoToggle);
- Spark.subscribe("Core3Toggle", ledTwoToggle2);
- }
- void loop()
- {
- static unsigned long lastPressTime =0;
- int val = digitalRead(inputPin);
- if (val == LOW && lastVal == HIGH)
- {
- if (millis() - lastPressTime > 25UL) //less primitive (non-blocking) debounce time
- {
- sendLedVal = !sendLedVal;
- digitalWrite(sendLedPin, sendLedVal ? HIGH : LOW);
- Spark.publish("Core1Toggle", sendLedVal ? "ON" : "OFF");
- }
- lastPressTime = millis();
- }
- lastVal = val;
- }
- void ledTwoToggle(const char *toggle, const char *onOff)
- {
- if (strcmp(onOff, "OFF") == 0)
- {
- digitalWrite(receiveLedPin, LOW);
- }
- else if (strcmp(onOff, "ON") == 0)
- {
- digitalWrite(receiveLedPin, HIGH);
- }
- }
- void ledTwoToggle2(const char *toggle, const char *onOff)
- {
- if (strcmp(onOff, "OFF") == 0)
- {
- digitalWrite(receiveLedPin2, LOW);
- }
- else if (strcmp(onOff, "ON") == 0)
- {
- digitalWrite(receiveLedPin2, HIGH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement