I thought I was doing a simple proof of concept between two cores for integration into my project, but I seem to be hung up on the subscribe end of things. My core running the publish code is publishing like its supposed to as seen via subscribe in the CLI. The other core is not responding with its led as expected. Thanks as always.
Publish Code:
const int switchPin = D0;
const int ledPin = D7;
int switchStatus = 0;
volatile bool high_flag= 0;
unsigned long startTime;
unsigned long duration = 5000;
void setup() {
pinMode(switchPin, INPUT_PULLDOWN);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
attachInterrupt(switchPin, switchHigh, RISING);
}
void loop() {
switchStatus = digitalRead(switchPin);
digitalWrite(ledPin, switchStatus);
if (high_flag) {
startTime = millis();
while(switchStatus == HIGH) {
switchStatus = digitalRead(switchPin);
if(millis() - startTime >= duration) {
Spark.publish("switch-status","alert");
delay(1000);
//break;
}
}
}
high_flag = 0;
}
void switchHigh() {
high_flag = 1;
}
Subscribe Code:
int led = LOW;
void dimmer(const char *event, const char *data) {
if(strcmp(data,"alert"))
led = HIGH;
else
led = LOW;
digitalWrite(D7, led);
}
void setup() {
pinMode(D7, OUTPUT);
Spark.subscribe("switch-status", dimmer);
}
void loop() {
digitalWrite(D7, led);
}