Hello guys!
I'm quite new to Photon and coding as well.
We're are trying to build a controller for an art piece and the eletronic part should be really simple:
We need to press one (or more) button on one Photon, in London, and light an (or more) assigned LED on a Photon in Congo. This has to be as Real Time as possible.
My questions at the moment are:
-Can I publish directly to another device or do I need IFTTT for this?
-Should I use Publish Event or Call a Function
These are the codes I have so far:
Publishing Photon:
int led = D7; // Uses inbuilt LED
int pushButton = D1; // Push button is connected to D1
// This routine runs only once upon reset
void setup()
{
pinMode(led, OUTPUT); // Initialize D7 pin as output
pinMode(pushButton, INPUT_PULLUP);
// Initialize D1 pin as input with an internal pull-up resistor
}
// This routine loops forever
void loop()
{
int pushButtonState;
pushButtonState = digitalRead(pushButton);
if(pushButtonState == LOW)
{ // If we push down on the push button
digitalWrite(led, HIGH); // Turn ON the LED
Spark.publish("pushButtonState","Pressed",60,PRIVATE);
// Add a delay to prevent getting tons of emails from IFTTT
delay(300);
}
else
{
digitalWrite(led, LOW); // Turn OFF the LED
}
}
.
Subscribing Photon:
int led_green = D1;
int led_yellow = D2;
void setup()
{
Serial.begin(9600);
pinMode(led_green, OUTPUT);
pinMode(led_yellow, OUTPUT);
Serial.println(Spark.subscribe("pressButton1State", greenOn, "230043000547343232363230"));
Serial.println(Spark.subscribe("pressButton2State", yellowOn));
}
void loop()
{
delay(200);
}
void greenOn(const char *event, const char *data)
{
digitalWrite(D7, HIGH);
}
void yellowOn(const char *event, const char *data)
{
digitalWrite(D7, HIGH);
}