Particle photon relay shield help

very new to the blynk world and also to the photon world, however ive made several arduino uno projects. my latest project uses a particle photon board with a 4 channel relay shield. i have the photon and shield working together online with the blynk app. i have four switches that activate each relay.

i would like some help trying to get the blynk buttons to work one at a time. so if you turn any button on it would come on as normal and if any other button was on it would deactivate. that way i only ever have one relay on at a time.

also i would like the relays and/or buttons to only stay on for a set amount of time and than turn off. im sure itll be done in code but just not sure how to set it up. the code i have is just the basic blynk sketch

#define BLYNK_PRINT Serial  // Set serial output for debug prints
//#define BLYNK_DEBUG       // Uncomment this to see detailed prints

#include <blynk.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "AUTH CODE";

// Attach a Button widget (mode: Switch) to the Digital pin 7 - and control the built-in blue led.
// Attach a Graph widget to Analog pin 1
// Attach a Gauge widget to Analog pin 2

void setup()
{
    Serial.begin(9600);
    delay(5000); // Allow board to settle

    Blynk.begin(auth);
}



void loop()
{
    Blynk.run();
}

Hello, and welcome to the Blynk forum. I had to edit your post so that the code was properly viewable…as per the Welcome Topic…

However, I am unsure why you included it anyhow, as there is nothing in it to show us what you have written that currently controls the relays… so I am guessing that you are using direct pin control, which will work for basics but not for anything fancier like what you are requesting… So coding and learning about virtual pins is necessary.

Start by reading up about Virtual Pins and then check out the various commands available to respond from and control the various App Widgets. All the relevant links are at the upper right of this page.

E.g. found in the Help Center - http://help.blynk.cc/blynk-basics/what-is-virtual-pins

Essentially what you want to do is use BLYNK_WRITE(vPIN) functions to respond to Button Widget state changes and then, as each function runs, it first physically turns off the other relays, turns on the corresponding relay and then tells the other buttons to act as if they were turned off, using the Blynk.virtualWrite(vPin, value).

E.g. A simple two button toggle example (showing code function for only one button).

BLYNK_WRITE(V1)  // Virtual button on V1, set as a switch, to activate corresponding relay.  This function gets automatically called at button state change.
{
  int RLY1 = param.asInt();  // Assign a value (0/1) to variable RLY1
    if (RLY1 == 1) {  // If RLY equals 1 then run these commands:
      digitalWrite(pinx, LOW);  // Deactivate corresponding relay
      digitalWrite(piny, HIGH);  // Activate corresponding relay
      Blynk.virtualWrite(V2, 0);  // Turn "OFF" virtual button set on V2 pin
    }
}

This is just one way of doing a quick and dirty, uncompiled/untested, example… read the documentation and play around with the various commands, and check out other examples in the Sketch Builder (link @ upper right of page), in order to best learn Blynk.

Have Fun!

thank you gunner for the reply, i did read the [readme] doc and was trying to get the code formatted right, i must have done something that posted my topic before i was able to format the code. i took your example and modified it to work and all is good. and repeated it for the other relays. now time to do some reading on timers. thx again for a point in the right direction.