0

M0 Feather ... Where to initialize a LED ?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

M0 Feather ... Where to initialize a LED ?

by MogaRaghu on Sun Apr 15, 2018 5:57 am

Reading my issue may raise eyebrows.. its simple. I have a M0 Bluefruit Feather and i am trying to add a LED to one of the examples. Funnily within Setup(void) , the position of the statement where i Declare the LED is critical or it seems so. Look at the attached code below in which the LED works as expected . But if i shift it below just before where Setup ends, it does not work. Any reason for this behaviour ??
Code: Select all | TOGGLE FULL SIZE
void setup(void)
{
  pinMode(ledFlash, OUTPUT);                        // If declared here the LED works !!
  digitalWrite( ledFlash, HIGH);

  Serial.begin(9600);
  Serial.println(F("Adafruit Bluefruit Command <-> Data Mode Example"));
  Serial.println(F("------------------------------------------------"));
  Serial.print(F("Initialising the Bluefruit LE module: "));
  if ( !ble.begin(VERBOSE_MODE) )       //  Start the BLE module.
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );
  ble.echo(false);
  Serial.println("Requesting Bluefruit info:");
  ble.info();
  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in UART mode"));
  Serial.println(F("Then Enter characters to send to Bluefruit"));
  Serial.println();
  ble.verbose(false);                 
  while (! ble.isConnected())         
  {
    delay(500);
  }
  Serial.println(F("******************************"));
  if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )   
  {
    Serial.println(F("Change LED activity to " MODE_LED_BEHAVIOUR));
    ble.sendCommandCheckOK("AT+HWModeLED=" MODE_LED_BEHAVIOUR); 
  }
  Serial.println( F("Switching to DATA mode!") );             
  ble.setMode(BLUEFRUIT_MODE_DATA);
  Serial.println(F("******************************"));

  //pinMode(ledFlash, OUTPUT);                                  // If  declared here, LED does not work !!
  //digitalWrite( ledFlash, HIGH);
}


MogaRaghu
 
Posts: 54
Joined: Mon Mar 13, 2017 8:37 pm

Re: M0 Feather ... Where to initialize a LED ?

by kcl1s on Sun Apr 15, 2018 8:18 am

This part of code will keep the LED from initializing (or run any more code) until you have a ble connection.

Code: Select all | TOGGLE FULL SIZE
  while (! ble.isConnected())         
  {
    delay(500);
  }


Fellow Hobbyist
Keith

kcl1s
 
Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: M0 Feather ... Where to initialize a LED ?

by MogaRaghu on Wed Apr 18, 2018 4:45 am

kcl1s wrote:This part of code will keep the LED from initializing (or run any more code) until you have a ble connection.

Code: Select all | TOGGLE FULL SIZE
  while (! ble.isConnected())         
  {
    delay(500);
  }


Fellow Hobbyist
Keith


Spot on. Missed that line !!

Thanks Keith.

MogaRaghu
 
Posts: 54
Joined: Mon Mar 13, 2017 8:37 pm

Please be positive and constructive with your questions and comments.