Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Simblee For Mobile / Re: SimbleeForMobile.drawSegment does not always work
« Last post by AKotowski on September 05, 2017, 07:04:44 AM »
Sorry, thats what I tried to do.  But then it works as in my post.  However in the SimbleeForMobile example files there is a sketch named SimbleeUITest.  This program demonstrates the problem.  In the Test switch/segmment API's a blue segment is displayed but all that is visible is a solid blue bar.  The bar works as a segment but just appears as a bar.  Some experimentation led to the realization that when a value is assigned to the segment, it displays as a solid blue bar.
22
Simblee For Mobile / Re: Update Segments on Connection
« Last post by tolson on September 04, 2017, 02:53:43 PM »
When using SimbleeForMobile, and you need responsiveness to the phone you can't really use ULPDelay or even long regular Delays as it will definitely interfere with it. You need to set up a series of pseudo state machines based on millis().

You can do something like this to get your strobe feature. I'm controlling it through the PWM instead of each LED enable.

Code: [Select]
bool strobe = true;

* * *

void loop()
{
  SimbleeForMobile.process();

  ledTime(); // deal with LED strobes, etc

  if(SimbleeForMobile.connected && SimbleeForMobile.updatable)
  {
    SimbleeForMobile.updateValue(ui_segment_front, frontValue);
    SimbleeForMobile.updateValue(ui_segment, brightnessValue);
  } 
}


* * *

int ledState = HIGH;
unsigned long previousMillis = 0;
unsigned long interval = 1000; // No const cause I want to change this dynamically.
unsigned long currentMillis;

void ledTime()
{
  if(strobe){
   
    currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      if (ledState == LOW) {
        ledState = HIGH;
        interval = 100;
        analogWrite(pwm_LED, brightness); // Turn ON LED
      } else {
        ledState = LOW;
        interval = 900;
        digitalWrite(pwm_LED, 0); // Turn OFF LED
      }
    }
   
  } else {
      analogWrite(pwm_LED, brightness); // no strobing
  }
}







23
Simblee For Mobile / Re: Update Segments on Connection
« Last post by hoser on September 04, 2017, 01:28:39 PM »
Thank you tolsen! I was just in the process of trying to figure out how to use the onConnected function to update the values but it kept bricking the Simblee. This worked perfectly. The only change I made was I defaulted the frontValue to 5 in order to not highlight any segment on the first time since no LEDs should be on when it is initially programmed.

The last thing I wanted to do was blink the selected LED and I am currently doing this in the main Loop using delays where I will turn the current_LED on, delay 100ms then off and delay 900ms. I know using a timer interrupt would be better suited. I'm hoping using a timer interrupt to change states will also make the app a little more responsive when connected. Because I have a 900ms delay, the app will populate and then update after a second. I created a switch that will change the strobe to 1 when selected and back to 0 when not selected. This updated value is used to determine if the current LED should be steady of blinking.


Code: [Select]
void loop()
{
  if (strobe == 1)
  {
    digitalWrite(current_LED, HIGH);
    delay(100);
    digitalWrite(current_LED, LOW);
    Simblee_ULPDelay(900);  // Put to sleep for 900ms
  }

  // This function must be called regularly to process UI events.
  SimbleeForMobile.process();

  if (SimbleeForMobile.connected && SimbleeForMobile.updatable)
  {
    SimbleeForMobile.updateValue(ui_segment_front, frontValue);
    SimbleeForMobile.updateValue(ui_segment, brightnessValue);
    SimbleeForMobile.updateValue(switchID_Blink, strobeValue);
  }
}
24
Simblee For Mobile / Re: SimbleeForMobile.drawSegment does not always work
« Last post by tolson on September 04, 2017, 12:38:38 PM »
Sorry, I am not following your description about some other sketch. Can you provide a minimum sketch showing exactly what you are describing.

The provided minimal sketch works and does not show what you are describing. The only problem I have with your sketch is the bright red on light grey is hard on the eyes to focus.
25
Simblee For Mobile / Re: Update Segments on Connection
« Last post by tolson on September 04, 2017, 12:21:21 PM »
Hi hoser,

You are almost there actually.

Just a quick note. Since you have defined your LEDs I changed your CASE statement to use those definitions instead of hard coding the GPIOs there. That way I was able to change the values in the definitions to match my LED locations.

Next in your ui_event you need to capture the values for later use. I used brightnessValue and frontValue.

Then in your loop you can test for phone connected AND that the UI is updatable before updating those value. Doing this will let you disconnect and come back and your UI Segments will reflect the values in your hardware.

Also, as a side affect, the default choices upon initial start up of the app is BLUE 25%. If you have a preference for what should be the initial startup you can change that in the brightnessValue and frontValue definition.

Code: [Select]

#include <SimbleeForMobile.h>

const int LED_WHITE = 2;
const int LED_RED = 5;
const int LED_BLUE = 17;
const int LED_GREEN = 6;
const int LED_YELLOW = 19;
int current_LED = 0;
const int pwm_LED = 4;
volatile uint32_t brightness = 65289; // This number divided by 255 is brightness (65,000 is brightest)
uint8_t intensityText;
uint8_t frontArrayText;
uint8_t blinkSwitchText;
uint8_t ui_segment;
uint8_t ui_segment_front;

uint8_t brightnessValue;
uint8_t frontValue;

void setup()
{
 
  pinMode(LED_WHITE, OUTPUT);
  digitalWrite(LED_WHITE, LOW);
  pinMode(LED_RED, OUTPUT);
  digitalWrite(LED_RED, LOW);
  pinMode(LED_BLUE, OUTPUT);
  digitalWrite(LED_BLUE, LOW);
  pinMode(LED_GREEN, OUTPUT);
  digitalWrite(LED_GREEN, LOW);
  pinMode(LED_YELLOW, OUTPUT);
  digitalWrite(LED_YELLOW, LOW);
  analogWrite(pwm_LED, brightness);

  SimbleeForMobile.advertisementData = "Demo";
  SimbleeForMobile.deviceName = "LED SEL";

  SimbleeForMobile.txPowerLevel = -4;

  SimbleeForMobile.begin();
}


void loop()
{
  SimbleeForMobile.process();

  if(SimbleeForMobile.connected && SimbleeForMobile.updatable)
  {
    SimbleeForMobile.updateValue(ui_segment_front, frontValue);
    SimbleeForMobile.updateValue(ui_segment, brightnessValue);
  }
 
}

void ui()
{
  color_t darkgray = rgb(13, 92, 199);

  uint16_t wid = SimbleeForMobile.screenWidth;
  uint16_t hgt = SimbleeForMobile.screenHeight;

  SimbleeForMobile.beginScreen(darkgray);

  frontArrayText = SimbleeForMobile.drawText(
                     (wid / 2) - 50,       // x location
                     (hgt / 2) - 200,       // y location
                     "FRONT ARRAY",           // text
                     WHITE);                // color of text

  const char* front_blue = "BLUE";
  const char* front_green = "GREEN";
  const char* front_yellow = "YELLOW";
  const char* front_red = "RED";
  const char* front_white = "WHITE";
  const char* const front_array[5] = {front_blue, front_green, front_yellow, front_red, front_white};

  ui_segment_front = SimbleeForMobile.drawSegment(
                       (wid / 2) - 150,        // x location
                       (hgt / 2) - 180,        // y location
                       300,                    // width
                       front_array,          // array
                       5,                      // count
                       WHITE);                 // color

  intensityText = SimbleeForMobile.drawText(
                    (wid / 2) - 33,         // x location
                    (hgt / 2) + 160,       // y location
                    "INTENSITY",           // text
                    WHITE);               // color of text


  const char* quarter = "25%";
  const char* half = "50%";
  const char* three_quarter = "75%";
  const char* full = "100%";
  const char* const segment_collection[4] = {quarter, half, three_quarter, full};

  ui_segment = SimbleeForMobile.drawSegment(
                 (wid / 2) - 100,        // x location
                 (hgt / 2) + 180,        // y location
                 200,                    // width
                 segment_collection,     // array
                 4,                      // count
                 WHITE);                 // color

  SimbleeForMobile.endScreen();
}

void ui_event(event_t &event)
{
  if (event.id == ui_segment)
  {
    brightnessValue = event.value;
    switch (brightnessValue)
    {
      case 0:
        brightness = 65535;
        break;
      case 1:
        brightness = 65500;
        break;
      case 2:
        brightness = 65430;
        break;
      case 3:
        brightness = 65289;
        break;
    }
    analogWrite(pwm_LED, brightness);
  }

  // Front array color selection
  if (event.id == ui_segment_front)
  {
    frontValue = event.value;
    switch (frontValue)
    {
      case 0:
        digitalWrite(LED_BLUE, HIGH);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = LED_BLUE;
        break;
      case 1:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, HIGH);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = LED_GREEN;
        break;
      case 2:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, HIGH);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = LED_WHITE;
        break;
      case 3:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, HIGH);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = LED_RED;
        break;
      case 4:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, HIGH);
        current_LED = LED_YELLOW;
        break;
    }
  }
}


26
Simblee For Mobile / Re: Update Segments on Connection
« Last post by hoser on September 04, 2017, 11:49:00 AM »
Are you intending to use the pwm_led to modulate a common line that goes to the 5 color LEDs? Or are you meaning to have a pwm level or the active color LED independant of the others.

But, basically you need to have a onConnect routine that re-sets your various values to the display.
You might have a onDisconnect routine that saves your values, but may not be necessary.




I am using the analogWrite function to control the intensity of a common anode to all 5 LEDs. This is done by the analog output driving a base of a NPN transistor which drives the gate of a P-channel FET. The cathode from each LED is fed into a N-channel FET which is controlled by the IO pin on the Simblee since my final device will have each LED draw around 50mA and cannot sink into the Simblee.
27
Simblee For Mobile / Re: Update Segments on Connection
« Last post by tolson on September 04, 2017, 10:34:56 AM »
Are you intending to use the pwm_led to modulate a common line that goes to the 5 color LEDs? Or are you meaning to have a pwm level or the active color LED independant of the others.

But, basically you need to have a onConnect routine that re-sets your various values to the display.
You might have a onDisconnect routine that saves your values, but may not be necessary.


28
Simblee For Mobile / Re: Update Segments on Connection
« Last post by AKotowski on September 04, 2017, 09:29:29 AM »
The way to do is is to update the value of the segment just after you draw it:  SimbleeForMobile.updateValue(segment, 1); .
See my post on this forum on Aug 30  http://forum.rfduino.com/index.php?topic=1804.0
29
Simblee For Mobile / Update Segments on Connection
« Last post by hoser on September 03, 2017, 09:48:50 PM »
I have created a program that has two separate segments, one with 5 segments and other with 4. The 5 value segment is used to select a different color LED (Blue, Green, Red, Yellow and White). The 4 value segment has intensity values for the LED (25%, 50%, 75%, 100%). Everything works correctly but what I am trying to do is update the selections when I reconnect to the Simblee.

For example if I have the Blue LED on with 50% intensity and close the app, the LED remains lit (which is what I want). When I reopen the app, the selections are defaulted to nothing and I would like it to automatically update the color segment to "Blue" and intensity segment to "50%". Would I use the "SimbleeForMobile_onConnect" function and a switch case based on the current selections? Also, how do you update a segment to select a value (segment is selected)? I have found many examples of updating other items but nothing for segments. I would also like to use this same method to default the selection to 100% when a new sketch is uploaded. By default, all the LEDs are off but the intensity is set to 100% even though it is not shown on the segment.

Any help is much appreciated.

Code: [Select]

#include <SimbleeForMobile.h>

const int LED_WHITE = 2;
const int LED_RED = 5;
const int LED_BLUE = 17;
const int LED_GREEN = 6;
const int LED_YELLOW = 19;
int current_LED = 0;
const int pwm_LED = 4;
volatile uint32_t brightness = 65289; // This number divided by 255 is brightness (65,000 is brightest)
uint8_t intensityText;
uint8_t frontArrayText;
uint8_t blinkSwitchText;
uint8_t ui_segment;
uint8_t ui_segment_front;


void setup()
{
  pinMode(LED_WHITE, OUTPUT);
  digitalWrite(LED_WHITE, LOW);
  pinMode(LED_RED, OUTPUT);
  digitalWrite(LED_RED, LOW);
  pinMode(LED_BLUE, OUTPUT);
  digitalWrite(LED_BLUE, LOW);
  pinMode(LED_GREEN, OUTPUT);
  digitalWrite(LED_GREEN, LOW);
  pinMode(LED_YELLOW, OUTPUT);
  digitalWrite(LED_YELLOW, LOW);
  analogWrite(pwm_LED, brightness);

  SimbleeForMobile.advertisementData = "Demo";
  SimbleeForMobile.deviceName = "LED SEL";

  SimbleeForMobile.txPowerLevel = -4;

  SimbleeForMobile.begin();
}

void loop()
{
  SimbleeForMobile.process();
}

void ui()
{
  color_t darkgray = rgb(13, 92, 199);

  uint16_t wid = SimbleeForMobile.screenWidth;
  uint16_t hgt = SimbleeForMobile.screenHeight;

  SimbleeForMobile.beginScreen(darkgray);

  frontArrayText = SimbleeForMobile.drawText(
                     (wid / 2) - 50,       // x location
                     (hgt / 2) - 200,       // y location
                     "FRONT ARRAY",           // text
                     WHITE);                // color of text

  const char* front_blue = "BLUE";
  const char* front_green = "GREEN";
  const char* front_yellow = "YELLOW";
  const char* front_red = "RED";
  const char* front_white = "WHITE";
  const char* const front_array[5] = {front_blue, front_green, front_yellow, front_red, front_white};

  ui_segment_front = SimbleeForMobile.drawSegment(
                       (wid / 2) - 150,        // x location
                       (hgt / 2) - 180,        // y location
                       300,                    // width
                       front_array,          // array
                       5,                      // count
                       WHITE);                 // color

  intensityText = SimbleeForMobile.drawText(
                    (wid / 2) - 33,         // x location
                    (hgt / 2) + 160,       // y location
                    "INTENSITY",           // text
                    WHITE);               // color of text


  const char* quarter = "25%";
  const char* half = "50%";
  const char* three_quarter = "75%";
  const char* full = "100%";
  const char* const segment_collection[4] = {quarter, half, three_quarter, full};

  ui_segment = SimbleeForMobile.drawSegment(
                 (wid / 2) - 100,        // x location
                 (hgt / 2) + 180,        // y location
                 200,                    // width
                 segment_collection,     // array
                 4,                      // count
                 WHITE);                 // color

  SimbleeForMobile.endScreen();
}

void ui_event(event_t &event)
{
  if (event.id == ui_segment)
  {
    switch (event.value)
    {
      case 0:
        brightness = 65535;
        break;
      case 1:
        brightness = 65500;
        break;
      case 2:
        brightness = 65430;
        break;
      case 3:
        brightness = 65289;
        break;
    }
    analogWrite(pwm_LED, brightness);
  }

  // Front array color selection
  if (event.id == ui_segment_front)
  {
    switch (event.value)
    {
      case 0:
        digitalWrite(LED_BLUE, HIGH);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = 17;
        break;
      case 1:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, HIGH);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = 6;
        break;
      case 2:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, HIGH);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = 2;
        break;
      case 3:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, HIGH);
        digitalWrite(LED_YELLOW, LOW);
        current_LED = 5;
        break;
      case 4:
        digitalWrite(LED_BLUE, LOW);
        digitalWrite(LED_GREEN, LOW);
        digitalWrite(LED_WHITE, LOW);
        digitalWrite(LED_RED, LOW);
        digitalWrite(LED_YELLOW, HIGH);
        current_LED = 19;
        break;
    }
  }
}
30
Support / Re: Cannot read I2C device inside Timer interrupt with SimbleeBLE initialized?!
« Last post by frogie on September 01, 2017, 07:53:18 AM »
After doing as much research on the Nordic forums as I could, I think this has something to do with interrupt priority inversion, something along the lines of the PPI internally used by the TWI library having a different interrupt priority if you're using the Soft Device (i.e. when radio is enabled) or not. Sadly I don't really know for sure.

In the meantime, I have gotten around the problem by delegating all my I2C operations to the main loop (using a small message queue of sorts). It means I can't really put anything else inside loop() (like main app logic) since it has to sit there and wait for messages like "Read Accelerator". A small inconvenience but I don't know of a better way right now.

I still would like to know for sure what exactly is going on though!
Pages: 1 2 [3] 4 5 ... 10