Author Topic: Control LED brightness through RFDuino Test app on android  (Read 658 times)

erketu

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Control LED brightness through RFDuino Test app on android
« on: July 22, 2016, 07:56:05 AM »
Hi guys. So I am completely new to Arduino software and RFDuino.

My LED is connected to RFDuino's GPIO pin and ground with a resistor. I want it to receive the value that I send from the RFDuino Test on my android app, and that value(number) would be converted to the value of analogWrite, which is 0 to 255. My code right now looks like this:

Code: [Select]
#include <RFduinoBLE.h>

int led = 2;           
uint32_t brightness;
void setup() {
  RFduinoBLE.deviceName = "RFDuino";
  Serial.begin(9600);
  RFduinoBLE.advertisementData = "LED";
  RFduinoBLE.begin();
  pinMode(led, OUTPUT);
}

void loop() {
  RFduino_ULPDelay(INFINITE);
}

void RFduinoBLE_onConnect() {
  analogWrite(led, 255);
}

void RFduinoBLE_onDisconnect() {
  digitalWrite(led, LOW);
}

void RFduinoBLE_onReceive(char *data, int len) {
    brightness = data[0];
    analogWrite(led, brightness);
    Serial.println(brightness);
}

I'm able to send values 0 to 99, and the LED brightness would increase from 0-99. However, it gets dimmer when I send value of 100. How would I be able to send value 0-255 and have analogWrite() to pick it up as the brightness?