Bluno to BLE Gamepad
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
Hi,
I have a Blune Beetle and a BLE Gamepad V2.
The BLuno is conenected to a string of WS2812b Leds. I am trying to write a sketch so when I press a button on the Gamepad the leds react.
I have managed to set the Gamepad as the CENTRAL and the Bluno as the PERIPHERAL. Made a unique BIND with the MAC address of the BLUNO.
When the Gamepad is switched on I get the 3 RX light blinks and then the 2 Rx light saying it is all connected.
When I press a button on the Gamepad the Tx light flashes which I think means they are communicating with each other.
However when I run the sketch below nothing happens.
I know it is not the led turning on and off code that is not working as it I have tested it on a none BLE comms sketch.
Any guidance would be appreciated
Many Thanks
Ian
I have a Blune Beetle and a BLE Gamepad V2.
The BLuno is conenected to a string of WS2812b Leds. I am trying to write a sketch so when I press a button on the Gamepad the leds react.
I have managed to set the Gamepad as the CENTRAL and the Bluno as the PERIPHERAL. Made a unique BIND with the MAC address of the BLUNO.
When the Gamepad is switched on I get the 3 RX light blinks and then the 2 Rx light saying it is all connected.
When I press a button on the Gamepad the Tx light flashes which I think means they are communicating with each other.
However when I run the sketch below nothing happens.
I know it is not the led turning on and off code that is not working as it I have tested it on a none BLE comms sketch.
Any guidance would be appreciated
Many Thanks
Ian
Code: Select all
// Binnoccio Heart Program - Bluno Beetle Test Code
// Basic Functions Vr4
// Used libraries:
#include <FastLED.h> // Include the FastLed Library
#include "DFRobotBLEGamepad.h" // Include the DFRobot BLE Gamepad Library
DFRobotBLEGamepad myDFRobotBLEGamepad; //init the bluetooth Serial port
// Define Constants
#define LED_PIN 5
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define NUM_LEDS 46
//Define Variables
byte LEDBrightness = 55;
int LEDMode = 0;
int LEDState = 0;
int joystickLeftX, joystickLeftY; //Left joystick value
// Define LED Array
CRGB leds[NUM_LEDS];
// ----------------------------------------------------------
void setup() {
// Soft Start
delay(2000);
Serial.begin(115200);
myDFRobotBLEGamepad.begin(Serial);
// Define the LED array "leds" parameters
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
// Pin Mode Setup
pinMode(LED_PIN, OUTPUT);
// Ensure LEDs off
// FastLED.setBrightness(LEDBrightness);
FastLED.clear();
FastLED.show();
myDFRobotBLEGamepad.ButtonUpIsPressed(switchUpEvent); // call the custom switch event function
myDFRobotBLEGamepad.ButtonDownIsPressed(switchDownEvent); // call the custom switch event function
} // End Setup
// ----------------------------------------------------------
void loop() {
if ( myDFRobotBLEGamepad.available() ) {
joystickLeftX = myDFRobotBLEGamepad.readJoystickLeftX();
joystickLeftY = myDFRobotBLEGamepad.readJoystickLeftY();
} // End If Serial Read
} // End loop
// ----------------------------------------------------------
void switchDownEvent( void ) {
FastLED.clear();
FastLED.show();
} // End switchDownEvent
// ----------------------------------------------------------
void switchUpEvent( void ) {
FillLEDs(0);
FastLED.show();
} // End switchUpEvent
// ----------------------------------------------------------
void FillLEDs(int x) {
// Fill 0 to (x-1) in blue
for (int j = 0; j < x ; j++) {
leds[j] = CRGB::Blue;
} // end for j loop
// fill from x to NUM_LEDS in red
for (int i = x; i < NUM_LEDS; i++) {
leds[i] = CRGB::Red;
} // end for i loop
} // End FillLEDs
// ----------------------------------------------------------