M0 Feather ... Where to initialize a LED ?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
MogaRaghu
 
Posts: 55
Joined: Mon Mar 13, 2017 8:37 pm

M0 Feather ... Where to initialize a LED ?

Post by MogaRaghu »

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

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); 
}


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

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

Post by kcl1s »

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

Code: Select all

  while (! ble.isConnected())          
  {
    delay(500);
  }
Fellow Hobbyist
Keith

User avatar
MogaRaghu
 
Posts: 55
Joined: Mon Mar 13, 2017 8:37 pm

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

Post by MogaRaghu »

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

  while (! ble.isConnected())          
  {
    delay(500);
  }
Fellow Hobbyist
Keith
Spot on. Missed that line !!

Thanks Keith.

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”