#if PLATFORM_ID == 6
//Photon code here
#define MY_FUNCTION(cloudFunctionID,localFunctionName) Particle.function(cloudFunctionID,localFunctionName)
#define MY_VARIABLE(cloudVariableID,localVariableName) Particle.variable(cloudVariableID,localVariableName)
// This #include statement was automatically added by the Particle IDE.
#include "NCD2Relay/NCD2Relay.h"
/*For relay control*/
NCD2Relay relayController;
/*Relay number*/
int relayNumber = 1;
/*Relay status*/
int rStatus = 0;
/***********************************Relay END**************************************/
int commandSent = 255;
void setup()
{
setupFunctions();
setupRelay();
}
void loop()
{
}
void setupFunctions()
{
MY_FUNCTION("Relay#",setRelayNumber);
MY_FUNCTION("RelayAction",setResetRelay);
}
void setupVariables()
{
}
void setupRelay()
{
Serial.begin(9600);
relayController.setAddress(0,0,0);
}
int setRelayNumber(String command)
{
if (command.length() != 1)
return -1;
relayNumber = atoi(command);
}
int setResetRelay(String command)
{
if (command.length() != 1)
return -1;
commandSent = atoi(command);
if (commandSent==1)
{
rStatus = relayController.readRelayStatus(relayNumber);
if(rStatus==0)
{
relayController.turnOnRelay(relayNumber);
}
return rStatus;
}
else if(commandSent==0)
{
rStatus = relayController.readRelayStatus(relayNumber);
if(rStatus==1)
{
relayController.turnOffRelay(relayNumber);
}
return rStatus;
}
}
#else
#error "*** PLATFORM_ID not supported by this library. PLATFORM should be Core or Photon ***"
#endif
Comments
Please log in or sign up to comment.