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?
Help Needed: RFduino LED Control for R G B
Re: Help Needed: RFduino LED Control for R G B
what you need to do is do a switch() statement
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:
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:
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.
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.
Re: Help Needed: RFduino LED Control for R G B
Thank you
It works!!
It works!!
Re: Help Needed: RFduino LED Control for R G B
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.
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.
Re: Help Needed: RFduino LED Control for R G B
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
http://forum.rfduino.com/index.php?topi ... 77#msg3777
Return to “Questions and answers”
Who is online
Users browsing this forum: No registered users and 46 guests