Help Needed: RFduino LED Control for R G B

Ask, and ye shall receive.
Amman
Posts: 14
Joined: 21:42, 19 Feb 2015

Help Needed: RFduino LED Control for R G B

Postby Amman » 22:45, 19 Feb 2015

Hi,

I have been working with the BLUE LED controlling App using the EVO Things client and workstation. Everything works great turning On and OFF the Blue LED on the RFduino shield using my Iphone.

I wanted to create additional buttons for the GREEN and RED Leds and do exactly the same as the Blue LED.
Succeeded in creating all the buttons and showing them up on the iphone, However I am totally lost on how to turn them on on the RFduino LED shield. Basically on the html code side, I have tried to modify the statement down here but I could not understand what the [1] and [0] represent.

// Turn on LED
app.ledOn = function()
{
app.device && app.device.writeDataArray(new Uint8Array([1]));

};

// Turn off LED.
app.ledOff = function()
{
app.device && app.device.writeDataArray(new Uint8Array([0]));

};

And I thought the above statement somehow corresponds to the following code on the Arduino side.
But I did not understand what "data" is and where it is coming from?

void RFduinoBLE_onReceive(char *data, int len)
{
// if the first byte is 0x01 / on / true
Serial.println("Received data over BLE");
if (data[0])
{
digitalWrite(BLUE_LED_PIN, HIGH);
Serial.println("Turn RFduino Blue LED On");
}
else
{
digitalWrite(BLUE_LED_PIN, LOW);
Serial.println("Turn RFduino Blue LED Off");
}
}

Can someone help me to add the RED and GREEN LED on/off buttons and make them work?


Thank you?

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: Help Needed: RFduino LED Control for R G B

Postby ardiri » 06:49, 20 Feb 2015

what you need to do is do a switch() statement

Code: Select all

switch (data[0])
{
  case 0: digitalWrite(BLUE_LED_PIN, LOW);
          Serial.println("Turn RFduino Blue LED Off");
          break;

  case 1: digitalWrite(BLUE_LED_PIN, HIGH);
          Serial.println("Turn RFduino Blue LED On");
          break;

  case 2: digitalWrite(RED_LED_PIN, LOW);
          Serial.println("Turn RFduino Red LED Off");
          break;

  case 3: digitalWrite(RED_LED_PIN, HIGH);
          Serial.println("Turn RFduino Red LED On");
          break;

  case 4: digitalWrite(GREEN_LED_PIN, LOW);
          Serial.println("Turn RFduino Green LED Off");
          break;

  case 5: digitalWrite(GREEN_LED_PIN, HIGH);
          Serial.println("Turn RFduino Green LED On");
          break;

  default:
          break;
}


and then modify the JavaScript code to send over the appropriate values - right now, it is only sending a 0 or 1 a based on the state:

Code: Select all

app.device && app.device.writeDataArray(new Uint8Array([0]));


the "[0]" is the number being passed over - so you need to create a few more JavaScript callbacks and define 2,3,4 and 5 as values such as:

Code: Select all

// Turn on Red LED
app.ledRedOn = function()
{
  app.device && app.device.writeDataArray(new Uint8Array([3]));
};


hopefully that makes sense :) the example probably isn't the clearest right now as the state for the LED is obscured in the if statement.
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/

Amman
Posts: 14
Joined: 21:42, 19 Feb 2015

Re: Help Needed: RFduino LED Control for R G B

Postby Amman » 18:22, 20 Feb 2015

Thank you

It works!! :D

tolson
Posts: 7
Joined: 03:33, 04 Mar 2015

Re: Help Needed: RFduino LED Control for R G B

Postby tolson » 07:41, 06 Mar 2015

HI Aaron,

I like what you have done here for the RFduino. Do you have a function to compliment the app.device.writeDataArray function to read the array sent from the RFduino? Something like app.device.readDataArray. I can't find it in the js libraries.

For example to read back the buttons on the RGB shield.
Thanks.

tolson
Posts: 7
Joined: 03:33, 04 Mar 2015

Re: Help Needed: RFduino LED Control for R G B

Postby tolson » 04:04, 09 Mar 2015

I've revamped the example to show the LED button color based on feedback from the RFduino sketch. I changed the way the LED indicates ON and OFF. I prefer the LED Button to be COLORED when the LED is ON and GRAY when the LED is OFF. I'm calling the changed version evoRGBv3. The .ino and .html is posted here...

http://forum.rfduino.com/index.php?topi ... 77#msg3777


Return to “Questions and answers”

Who is online

Users browsing this forum: Google [Bot] and 9 guests