Advertisement
Guest User

Core 1

a guest
Nov 8th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. int sendLedPin = D7;
  2. int inputPin = D4;
  3. int receiveLedPin = D0;
  4. int receiveLedPin2 = D6;
  5. int lastVal = 0;
  6. int sendLedVal = 0;
  7. void ledTwoToggle(const char *toggle, const char *onOff); //handler function for Spark.subscribe()
  8.  
  9.  
  10. void setup()
  11. {
  12.   pinMode(receiveLedPin, OUTPUT);
  13.   pinMode(receiveLedPin2, OUTPUT);
  14.   pinMode(sendLedPin, OUTPUT);
  15.   pinMode(inputPin, INPUT_PULLUP);
  16.   digitalWrite(sendLedPin, LOW);
  17.   digitalWrite(receiveLedPin, LOW);
  18.   digitalWrite(receiveLedPin2, LOW);
  19.   Spark.publish("Core1Toggle", "State", 0);
  20.   Spark.subscribe("Core2Toggle", ledTwoToggle);
  21.   Spark.subscribe("Core3Toggle", ledTwoToggle2);
  22. }
  23.  
  24.  
  25. void loop()
  26. {
  27.   static unsigned long lastPressTime =0;
  28.   int val = digitalRead(inputPin);
  29.   if (val == LOW && lastVal == HIGH)
  30.   {
  31.     if (millis() - lastPressTime > 25UL) //less primitive (non-blocking) debounce time
  32.     {
  33.       sendLedVal = !sendLedVal;
  34.       digitalWrite(sendLedPin, sendLedVal ? HIGH : LOW);
  35.       Spark.publish("Core1Toggle", sendLedVal ? "ON" : "OFF");
  36.     }
  37.     lastPressTime = millis();
  38.   }
  39.   lastVal = val;
  40. }
  41.  
  42. void ledTwoToggle(const char *toggle, const char *onOff)
  43. {
  44.   if (strcmp(onOff, "OFF") == 0)
  45.   {
  46.     digitalWrite(receiveLedPin, LOW);
  47.   }
  48.   else if (strcmp(onOff, "ON") == 0)
  49.   {
  50.     digitalWrite(receiveLedPin, HIGH);
  51.   }
  52. }
  53.  
  54. void ledTwoToggle2(const char *toggle, const char *onOff)
  55. {
  56.   if (strcmp(onOff, "OFF") == 0)
  57.   {
  58.     digitalWrite(receiveLedPin2, LOW);
  59.   }
  60.   else if (strcmp(onOff, "ON") == 0)
  61.   {
  62.     digitalWrite(receiveLedPin2, HIGH);
  63.   }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement