Author Topic: RFduino Gzll Sleep Mode  (Read 2660 times)

Remsey

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
RFduino Gzll Sleep Mode
« on: March 06, 2014, 05:05:49 AM »
Hello how can i geht the rfduino put to sleep mode or ultra low power mode

here is the code which i use

#include <RFduinoGZLL.h>

device_t role = DEVICE0;

// pin for Button A on the RGB Shield
int button_a = 5;

// debounce time (in ms)
int debounce_time = 10;

// maximum debounce timeout (in ms)
int debounce_timeout = 100;

// starting state is off
char state = 0;

void setup()
{
  pinMode(button_a, INPUT);

  // start the GZLL stack
  RFduinoGZLL.begin(role);
}

int debounce(int button, int state)
{
  int start = millis();
  int debounce_start = start;
 
  while (millis() - start < debounce_timeout)
    if (digitalRead(button) == state)
    {
      if (millis() - debounce_start >= debounce_time)
        return 1;
    }
    else
      debounce_start = millis();

  return 0;
}

int delay_until_button(int button, int state)
{
  while (! debounce(button, state))
    ;
}

void loop()
{
  delay_until_button(button_a, HIGH);
 
  // toggle state
  state = ! state;

  // send state to Host
  RFduinoGZLL.sendToHost(state);
 
  delay_until_button(button_a, LOW);
}

void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
}

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: RFduino Gzll Sleep Mode
« Reply #1 on: March 06, 2014, 08:56:25 AM »
Hi, You can use RFduino_ULPDelay in the main loop and use PinWake to wake it up out of ULPDelay when a button is pressed.  Something like this...

pinMode(5, INPUT);
RFduino_pinWake(5, HIGH);


RFduino_ULPDelay(INFINITE);
 if (RFduino_pinWoke(5))
  {
    state = ! state;
    RFduinoGZLL.sendToHost(state);
  }


See the PinWake (non BLE example) for some more info on how PinWake and PinWoke work.