drishya k

drishya k

  • NA
  • 4
  • 2k

controlling two leds using two switches with homegenie

Mar 8 2017 1:11 AM
i have controlled green led and red led using arduino with serial monitor.  Now i need to control leds using Homegenie and arduino. But in homegenie only C# program support for .hgx file . i hve an arduino program to control two leds and that is attaching with this  post. Can anyone pls help to write corresponding C# program for this.
 
 Program:
 
typedef int8_t tSI8;
typedef uint8_t tUI8;
enum
{
FALSE = 0u, TRUE
};
/* TRUE = 1 */
/* ============================================================================
* Private Constants
* ==========================================================================*/
static const tUI8 buttonPin = 2; /* the number of the pushbutton pin */
static tUI8 ledPin1 = 4; /* the number of the LED pin green*/
static tUI8 ledPin2 = 6; /* the number of the LED pin red */
/* ============================================================================
* Private variables
* ==========================================================================*/
static String inputString = ""; /* a string to hold incoming data */
static tUI8 buttonState = FALSE; /* variable for reading the pushbutton status */
static tUI8 last_state = FALSE;
static tUI8 DATA_OUT = FALSE;
/* ============================================================================
* Functions
* ==========================================================================*/
/*****************************************************************************/
/** \brief setup() only runs once after boot
*****************************************************************************/
void setup()
{
/* initialize serial/UART port */
Serial.begin(9600u);
/* reserve 200 bytes for the inputString */
inputString.reserve(200u);
/* init pins */
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
/*****************************************************************************/
/** \brief Loop runs till there is power.
*****************************************************************************/
void loop()
{
/* check if the pushbutton is pressed. */
/* if it is, the buttonState is LOW (inverting) */
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin2, !buttonState); /* visual feedback */
if ((buttonState != last_state) && (last_state != FALSE))
{
DATA_OUT = !DATA_OUT; /* invert state */
Serial.println(DATA_OUT);
}
last_state = buttonState; /* Update falling edge detection */
}
/*****************************************************************************/
/** \brief Handle UART/serial data reception
*
* SerialEvent occurs whenever a new data comes in the
* hardware serial RX. This routine is run between each
* time loop() runs, so using delay inside loop can delay
* response. Multiple bytes of data may be available.
*****************************************************************************/
void serialEvent()
{
while (Serial.available())
{
/* get the new byte: */
char inChar = (char) Serial.read();
/* Change Output pin state (now Green LED) based on what has been received */
if (inChar == '0')
{
digitalWrite(ledPin1, LOW);
} else if(inChar == '1')/* anything but '0' char received */
{
digitalWrite(ledPin1, HIGH);
}
}
}