What does If statement stop program from progressing?

I am trying to run a modified sketch inside a preexisting sketch. The FM transmitter is the portion I am adding. At the start it looks for a connection to the radio and it did have While (1) at the end of the if statement that I removed as it would stop the program. I have replaced this with setting an LED if the statement fails. So if the transmitter is not attached an LED turns on and the program proceeds. If the radio is attached the program does not pass the if statement. No transmitter connected the serial monitor shows all the serial print messages and proceeds into the void loop. Transmitter connected it serial prints adadfruit radio Si4713 Test and the code does not move past it. I want the code to proceed no matter the state of the radio, the LED will let me know if it failed. Which seems similar to the above situation. I have tried adding in an else statement but it produced the same result.
What am I missing here? And thank you in advance!

void setup() {
  
  // Serial connection used to print debug values
  Serial.begin(9600);

  //FM Transmitter
  Serial.println("Adafruit Radio - Si4713 Test");

  //fm transmiter fail LED
  pinMode(LED, OUTPUT);
  if (! radio.begin()) {  // begin with address 0x63 (CS high default)
    Serial.println("Couldn't find radio?");
    digitalWrite(LED, HIGH);
  }
  // Uncomment to scan power of entire range from 87.5 to 108.0 MHz
  /*
  for (uint16_t f  = 8750; f<10800; f+=10) {
   radio.readTuneMeasure(f);
   Serial.print("Measuring "); Serial.print(f); Serial.print("...");
   radio.readTuneStatus();
   Serial.println(radio.currNoiseLevel);
   }
   */

  Serial.print("\nSet TX power");
  radio.setTXpower(115);  // dBuV, 88-115 max

  Serial.print("\nTuning into "); 
  Serial.print(FMSTATION/100); 
  Serial.print('.'); 
  Serial.println(FMSTATION % 100);
  radio.tuneFM(FMSTATION); // 102.3 mhz

  // This will tell you the status in case you want to read it from the chip
  radio.readTuneStatus();
  Serial.print("\tCurr freq: "); 
  Serial.println(radio.currFreq);
  Serial.print("\tCurr freqdBuV:"); 
  Serial.println(radio.currdBuV);
  Serial.print("\tCurr ANTcap:"); 
  Serial.println(radio.currAntCap);

  // begin the RDS/RDBS transmission
  radio.beginRDS();
  radio.setRDSstation("AdaRadio");
  radio.setRDSbuffer( "Adafruit g0th Radio!");

  Serial.println("RDS on!");  

  radio.setGPIOctrl(_BV(1) | _BV(2));  // set GP1 and GP2 to output

  // Loop over and initialise all the MAX72XX modules
  for(int i=0; i<4; i++){
    lc.shutdown(i,false);
    lc.setIntensity(i,5);
    lc.clearDisplay(i);
    lc.setIntensity(i,0);
  }

  // Intialise the input pins
  for(int i=0; i<4; i++){
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  pinMode(submitPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);

  FastLED.addLeds<WS2812B, A2, GRB>(leds, numLeds);

  // Uncomment the following line if you'd like to set a random secret code
  setRandomSecret();
}

If the radio initialization fails do you want to do radio stuff afterwards?

  if (! radio.begin()) {  // begin with address 0x63 (CS high default)
    Serial.println("Couldn't find radio?");
    digitalWrite(LED, HIGH);
  } else {
  // Uncomment to scan power of entire range from 87.5 to 108.0 MHz
  /*
  for (uint16_t f  = 8750; f<10800; f+=10) {
   radio.readTuneMeasure(f);
   Serial.print("Measuring "); Serial.print(f); Serial.print("...");
   radio.readTuneStatus();
   Serial.println(radio.currNoiseLevel);
   }
}
   */

Something like that, if the radio fails do a serial print otherwise do the radio stuff.

Hello,
Right now I am just trying to isolate out the radio section, so it does what it does and then it runs the below no matter what and transitions into the void loop.

// Loop over and initialise all the MAX72XX modules
  for(int i=0; i<4; i++){
    lc.shutdown(i,false);
    lc.setIntensity(i,5);
    lc.clearDisplay(i);
    lc.setIntensity(i,0);
  }
  
  // Intialise the input pins
  for(int i=0; i<4; i++){
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  pinMode(submitPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);

  FastLED.addLeds<WS2812B, A2, GRB>(leds, numLeds);

  // Uncomment the following line if you'd like to set a random secret code
  setRandomSecret();
}

void loop() {

Anytime the if statement is present it does not seem to run the above or the void loop. Starting to think my use of {} is wrong

Put a serial print at the top of loop() to prove its not running.

Serial.println("look Ima running the thing");

If you code

if (! radio.begin()

...

Never mind, could you start over and post all your code? I'd like to take a look at the radio library you are using, myself, so I can see how to properly use the library.

Sure :)
I am going to post 2 sets of code. First is the example code on the radio, second is the main program. The main program randomizes a secret number that will be used to set the FM frequency. I can run either code with no issues on the same Arduino Nano with no change in wiring.
When I add the void set up functions of the radio to the main code the while (1) statement stops the code if the radio is not seen. I tried to change this and things fell apart. Any manipulation I did any code after the radio did not run including I think the void loop. I have done a lot of reading and looking at examples and this should work with no issues.
I will need to send another message with the code, exceeded the limit. So 5 minutes...

// For controlling Neopixel LED strips - download from http://fastled.io/
#include <FastLED.h>
// Used to control a panel of MAX7219 LED displays showing the input sequence - https://github.com/wayoda/LedControl
#include "LedControl.h"
// Used to form structured JSON output to send via serial connection - https://arduinojson.org/
#include <ArduinoJson.h>
// Header file contains definition of the values appeaing on the display
#include "font.h"
//FM Trasmitter lib 1
#include <Adafruit_Si4713.h>
//FM Transmitter lib 2
#include <Wire.h>
//FM Trasmitter
//#define _BV(n) (1 << n)
//#define RESETPIN 12
//#define FMSTATION 10230 

// CONSTANTS
// Define the Arduino pins to which buttons are attached
const byte buttonPins[] = {2, 3, 4, 5};
const byte submitPin = 6;
// This pin will be sent a HIGH pulse when the correct solution is entered
const byte relayPin = A3;
// Number of values in the secret code
const byte codeLength = 4;
// The number of different types of symbol from which the code is made
const byte numSymbols = 10;
// The number of LEDs used to provide feedback on each guess
const byte numLeds=32;
//FM transmitter
//Adafruit_Si4713 radio = Adafruit_Si4713(RESETPIN);


// GLOBALS
// Initialise a LedControl object
// Parameters are DataIn (Din), Clock (Clk), ChipSelect (CS), Number of MAX72XX modules
LedControl lc = LedControl(A1, 13, A0, 4);
// Keep track of which buttons were pressed last frame
bool lastButtonState[codeLength];
// The secret code players are trying to guess.
// This is an array of byte values, each between 0 and numSymbols-1
// The actual image displayed for each element is defined by the array in the font.h file
byte secret[codeLength] = {1,0,0,0};
// The player's guess
byte guess[codeLength];
// The number of guesses made
int numGuesses = 0;
// Define the array of leds used to provide feedback
CRGB leds[numLeds];


void setRandomSecret() {
  // Create seed value based on random noise on unconnected analog input pin
  randomSeed(analogRead(A5));
  //set to an fm frequency
  int randset = random(101) *2 + 879;
  int fmstation[4];
  secret[0] = (randset/ 1000) % 10;
  secret[1] = (randset / 100) % 10;
  secret[2] = (randset / 10) % 10;
  secret[3] = (randset / 1) % 10;
  
}

/**
 * Displays the response (blacks and whites) to a player's guess
 */
void displayResponse(int numBlacks, int numWhites){

  // Loop to allow flashing of "white" pegs
  for(int loop=0; loop<7; loop++){
    // Colour in a quarter of all LEDs for each correct "black" peg
    for(int i=0; i<numBlacks*(numLeds/4); i++) {
      leds[i] = CRGB::Blue;
    }
    // Now colour in a quarter of remaining LEDs for each "white" peg in the guess
    for(int i=numBlacks*(numLeds/4); i<(numBlacks+numWhites)*(numLeds/4); i++) {
      // Alternate between black and orange
      leds[i] = (loop%2) ? CRGB::Black : CRGB::Red;
    }
    FastLED.show();
    delay(200);
  }

  // Turn off all the LEDs again
  for(int i=0; i<numLeds; i++){
    leds[i] = CRGB::Black;
  }
  FastLED.show(); 
}

/**
 * Send details of a guess and its response as JSON over serial connection 
 */
bool serialUpdate(byte secret[], byte guess[], byte blackCount, byte whiteCount){
  // Create a JSON document of sufficient size
  StaticJsonDocument<256> doc;
  // Include a unique ID to identify this puzzle
  doc["id"] = "Mastermind";
  // Create a simple property with the number of guesses
  doc["turn"] = numGuesses;
  // Include the secret code as an array of elements
  JsonArray jsonSecret = doc.createNestedArray("secret");
  for(int i=0;i<4; i++) { jsonSecret.add(secret[i]); }
  // Include the player's last guess
  JsonArray jsonGuess = doc.createNestedArray("guess");
  for(int i=0;i<4; i++) { jsonGuess.add(guess[i]); }
  // Create an array containing the response of blacks and whites
  JsonArray result = doc.createNestedArray("result");
  result.add(blackCount);
  result.add(whiteCount);
  doc["state"] = (blackCount == codeLength) ? "SOLVED" : "UNSOLVED" ;
  // Send the result over the serial connection
  serializeJson(doc, Serial);
  Serial.println("");
}

/**
 * Compares the player's last guess to the stored secret code
 */
bool calculateResponse(byte &blackCount, byte &whiteCount) {

  // Keep track of which elements have already been scored
  bool secretUsed[codeLength] = {false, };// = {false, false, false, false};
  bool guessUsed[codeLength] = {false, };//= {false, false, false, false};

  // Count "black" - correct values in correct positions
  blackCount = 0;
  for (int i=0; i<codeLength; i++) {
    if (guess[i] == secret[i]) {
      blackCount++;
      secretUsed[i] = true;
      guessUsed[i] = true;
    } 
  }

  // Count "white" - correct values in *incorrect* position
  whiteCount = 0;
  for (int i=0; i<codeLength; i++) {
    // Don't score elements from guess already counted as black hits
    if(!guessUsed[i]) {
      for(int j=0; j<codeLength; j++) {
        // Don't score elements from secret already counted as black hits
        if(!secretUsed[j] && (guess[i] == secret[j])) {
          whiteCount++;
          // Mark to ensure this element is not double-counted
          secretUsed[j] = true;
          break;
        }
      }
    }
  }

  // Call the serial update function   
  serialUpdate(secret, guess, blackCount, whiteCount);

  // Return true if code was correct
  return (blackCount == codeLength);
}

/**
 * Reads player input to guess the secret code
 */
void getInput() {

  // For testing, use the following code to enter input via serial monitor
  /*
  int counter=0;
  // Wait until something is received
  while (!Serial.available());
  while(true) {
    char incomingByte = Serial.read();
    if (incomingByte == '\n' || incomingByte == '\r') { break; } // exit the while(1), we're done receiving
    if (incomingByte == -1) { continue; } // if no characters are in the buffer read() returns -1
    guess[counter] = (incomingByte - 48);
    counter++;
    if(counter >= codeLength) { break; }
  }
  */

  // Ensure that submit button is not being held down to prevent double-submits
  while(!digitalRead(submitPin)) {
    delay(100);
  }
  // Loop until the submit button is pressed
  while(digitalRead(submitPin)) {
    for(int i=0; i<4; i++){
      // Read each button input
      bool buttonState = digitalRead(buttonPins[i]);
      // If the button wasn't pressed last frame, but is now
      if(!buttonState && lastButtonState[i]) {
        // Increase the value of this guess element
        guess[i]++;
        // And, if the value goes out of allowed range, wrap back to 0
        if(guess[i]>=numSymbols) { guess[i] = 0; }
      }
      // Update the last state for this button
      lastButtonState[i] = buttonState;
      // Display the guess on the LED matrix
      for(int row=0; row<8; row++){
        lc.setRow(i,row,digits[guess[i]][row]);
      }
    }
  }
}

void setup() {
  
    Serial.begin(9600);
  
  for(int i=0; i<4; i++){
    lc.shutdown(i,false);
    lc.setIntensity(i,5);
    lc.clearDisplay(i);
    lc.setIntensity(i,0);
  }

  // Intialise the input pins
  for(int i=0; i<4; i++){
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  pinMode(submitPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);

  FastLED.addLeds<WS2812B, A2, GRB>(leds, numLeds);

    setRandomSecret();
}

void loop() {
  // Wait for the player to input a guess
  getInput();
  // Check their guess against the correct code
  byte whiteCount=0, blackCount=0;
  calculateResponse(blackCount, whiteCount);

  // Correct code entered
  if(blackCount == codeLength) {
    // Unlock a maglock, flash a light, whatever...
    digitalWrite(relayPin, HIGH);
    delay(50);
    digitalWrite(relayPin, LOW);
    
    // Serial monitor
    Serial.print(F("YOU WIN!"));

    // Chase sequence  
    for(int i=0; i<numLeds; i++){
      leds[i] = CRGB::Green;
      FastLED.show();
      delay(20);
    }
    for(int i=0; i<numLeds; i++){
      leds[i] = CRGB::Black;
      FastLED.show();
      delay(20);
    }
  }
  // Incorrect guess
  else {
    displayResponse(blackCount, whiteCount);
  }

  // If desired, heep count of the number of guesses
  numGuesses++;  
}

Below is the example code for the transmitter:

// For controlling Neopixel LED strips - download from http://fastled.io/
#include <FastLED.h>
// Used to control a panel of MAX7219 LED displays showing the input sequence - https://github.com/wayoda/LedControl
#include "LedControl.h"
// Used to form structured JSON output to send via serial connection - https://arduinojson.org/
#include <ArduinoJson.h>
// Header file contains definition of the values appeaing on the display
#include "font.h"
//FM Trasmitter lib 1
#include <Adafruit_Si4713.h>
//FM Transmitter lib 2
#include <Wire.h>
//FM Trasmitter
//#define _BV(n) (1 << n)
//#define RESETPIN 12
//#define FMSTATION 10230 

// CONSTANTS
// Define the Arduino pins to which buttons are attached
const byte buttonPins[] = {2, 3, 4, 5};
const byte submitPin = 6;
// This pin will be sent a HIGH pulse when the correct solution is entered
const byte relayPin = A3;
// Number of values in the secret code
const byte codeLength = 4;
// The number of different types of symbol from which the code is made
const byte numSymbols = 10;
// The number of LEDs used to provide feedback on each guess
const byte numLeds=32;
//FM transmitter
//Adafruit_Si4713 radio = Adafruit_Si4713(RESETPIN);


// GLOBALS
// Initialise a LedControl object
// Parameters are DataIn (Din), Clock (Clk), ChipSelect (CS), Number of MAX72XX modules
LedControl lc = LedControl(A1, 13, A0, 4);
// Keep track of which buttons were pressed last frame
bool lastButtonState[codeLength];
// The secret code players are trying to guess.
// This is an array of byte values, each between 0 and numSymbols-1
// The actual image displayed for each element is defined by the array in the font.h file
byte secret[codeLength] = {1,0,0,0};
// The player's guess
byte guess[codeLength];
// The number of guesses made
int numGuesses = 0;
// Define the array of leds used to provide feedback
CRGB leds[numLeds];


void setRandomSecret() {
  // Create seed value based on random noise on unconnected analog input pin
  randomSeed(analogRead(A5));
  //set to an fm frequency
  int randset = random(101) *2 + 879;
  int fmstation[4];
  secret[0] = (randset/ 1000) % 10;
  secret[1] = (randset / 100) % 10;
  secret[2] = (randset / 10) % 10;
  secret[3] = (randset / 1) % 10;
  
}

/**
 * Displays the response (blacks and whites) to a player's guess
 */
void displayResponse(int numBlacks, int numWhites){

  // Loop to allow flashing of "white" pegs
  for(int loop=0; loop<7; loop++){
    // Colour in a quarter of all LEDs for each correct "black" peg
    for(int i=0; i<numBlacks*(numLeds/4); i++) {
      leds[i] = CRGB::Blue;
    }
    // Now colour in a quarter of remaining LEDs for each "white" peg in the guess
    for(int i=numBlacks*(numLeds/4); i<(numBlacks+numWhites)*(numLeds/4); i++) {
      // Alternate between black and orange
      leds[i] = (loop%2) ? CRGB::Black : CRGB::Red;
    }
    FastLED.show();
    delay(200);
  }

  // Turn off all the LEDs again
  for(int i=0; i<numLeds; i++){
    leds[i] = CRGB::Black;
  }
  FastLED.show(); 
}

/**
 * Send details of a guess and its response as JSON over serial connection 
 */
bool serialUpdate(byte secret[], byte guess[], byte blackCount, byte whiteCount){
  // Create a JSON document of sufficient size
  StaticJsonDocument<256> doc;
  // Include a unique ID to identify this puzzle
  doc["id"] = "Mastermind";
  // Create a simple property with the number of guesses
  doc["turn"] = numGuesses;
  // Include the secret code as an array of elements
  JsonArray jsonSecret = doc.createNestedArray("secret");
  for(int i=0;i<4; i++) { jsonSecret.add(secret[i]); }
  // Include the player's last guess
  JsonArray jsonGuess = doc.createNestedArray("guess");
  for(int i=0;i<4; i++) { jsonGuess.add(guess[i]); }
  // Create an array containing the response of blacks and whites
  JsonArray result = doc.createNestedArray("result");
  result.add(blackCount);
  result.add(whiteCount);
  doc["state"] = (blackCount == codeLength) ? "SOLVED" : "UNSOLVED" ;
  // Send the result over the serial connection
  serializeJson(doc, Serial);
  Serial.println("");
}

/**
 * Compares the player's last guess to the stored secret code
 */
bool calculateResponse(byte &blackCount, byte &whiteCount) {

  // Keep track of which elements have already been scored
  bool secretUsed[codeLength] = {false, };// = {false, false, false, false};
  bool guessUsed[codeLength] = {false, };//= {false, false, false, false};

  // Count "black" - correct values in correct positions
  blackCount = 0;
  for (int i=0; i<codeLength; i++) {
    if (guess[i] == secret[i]) {
      blackCount++;
      secretUsed[i] = true;
      guessUsed[i] = true;
    } 
  }

  // Count "white" - correct values in *incorrect* position
  whiteCount = 0;
  for (int i=0; i<codeLength; i++) {
    // Don't score elements from guess already counted as black hits
    if(!guessUsed[i]) {
      for(int j=0; j<codeLength; j++) {
        // Don't score elements from secret already counted as black hits
        if(!secretUsed[j] && (guess[i] == secret[j])) {
          whiteCount++;
          // Mark to ensure this element is not double-counted
          secretUsed[j] = true;
          break;
        }
      }
    }
  }

  // Call the serial update function   
  serialUpdate(secret, guess, blackCount, whiteCount);

  // Return true if code was correct
  return (blackCount == codeLength);
}

/**
 * Reads player input to guess the secret code
 */
void getInput() {

  // For testing, use the following code to enter input via serial monitor
  /*
  int counter=0;
  // Wait until something is received
  while (!Serial.available());
  while(true) {
    char incomingByte = Serial.read();
    if (incomingByte == '\n' || incomingByte == '\r') { break; } // exit the while(1), we're done receiving
    if (incomingByte == -1) { continue; } // if no characters are in the buffer read() returns -1
    guess[counter] = (incomingByte - 48);
    counter++;
    if(counter >= codeLength) { break; }
  }
  */

  // Ensure that submit button is not being held down to prevent double-submits
  while(!digitalRead(submitPin)) {
    delay(100);
  }
  // Loop until the submit button is pressed
  while(digitalRead(submitPin)) {
    for(int i=0; i<4; i++){
      // Read each button input
      bool buttonState = digitalRead(buttonPins[i]);
      // If the button wasn't pressed last frame, but is now
      if(!buttonState && lastButtonState[i]) {
        // Increase the value of this guess element
        guess[i]++;
        // And, if the value goes out of allowed range, wrap back to 0
        if(guess[i]>=numSymbols) { guess[i] = 0; }
      }
      // Update the last state for this button
      lastButtonState[i] = buttonState;
      // Display the guess on the LED matrix
      for(int row=0; row<8; row++){
        lc.setRow(i,row,digits[guess[i]][row]);
      }
    }
  }
}

void setup() {
  
  // Serial connection used to print debug values
  Serial.begin(9600);
  
  // Loop over and initialise all the MAX72XX modules
  for(int i=0; i<4; i++){
    lc.shutdown(i,false);
    lc.setIntensity(i,5);
    lc.clearDisplay(i);
    lc.setIntensity(i,0);
  }

  // Intialise the input pins
  for(int i=0; i<4; i++){
    pinMode(buttonPins[i], INPUT_PULLUP);
  }
  pinMode(submitPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);

  FastLED.addLeds<WS2812B, A2, GRB>(leds, numLeds);

  // Uncomment the following line if you'd like to set a random secret code
  setRandomSecret();
}

void loop() {
  // Wait for the player to input a guess
  getInput();
  // Check their guess against the correct code
  byte whiteCount=0, blackCount=0;
  calculateResponse(blackCount, whiteCount);

  // Correct code entered
  if(blackCount == codeLength) {
    // Unlock a maglock, flash a light, whatever...
    digitalWrite(relayPin, HIGH);
    delay(50);
    digitalWrite(relayPin, LOW);
    
    // Serial monitor
    Serial.print(F("YOU WIN!"));

    // Chase sequence  
    for(int i=0; i<numLeds; i++){
      leds[i] = CRGB::Green;
      FastLED.show();
      delay(20);
    }
    for(int i=0; i<numLeds; i++){
      leds[i] = CRGB::Black;
      FastLED.show();
      delay(20);
    }
  }
  // Incorrect guess
  else {
    displayResponse(blackCount, whiteCount);
  }

  // If desired, heep count of the number of guesses
  numGuesses++;  
}

In the code you just posted where is the if statement giving issues?

In the example code

if (! radio.begin()) { // begin with address 0x63 (CS high default)Serial.println("Couldn't find radio?");
while (1);}

The idea is not to continue if the radio is not working. Or don't run radio code if radio is not there.

So if the if statement is NOT letting the code past that point, it's because the radio is not there.

When you ran just the example code did the radio work?

Yes both codes work perfectly when ran on their own with the exact same hardware. Standalone its fine that the radio does not continue, and yes I am referring to the line of code you mentioned. But when I add the radio to the main program I want everything to run no matter of the state of the radio, but I would like to turn on an LED if the radio does not connect. This is why I removed the While and added in an LED on pin 7 earlier.

scouser1023:
Yes both codes work perfectly when ran on their own with the exact same hardware.

But when I add the radio to the main program I want everything to run no matter of the state of the radio, but I would like to turn on an LED if the radio does not connect.

If the radio is running, as I posted above, do one thing. if it is not running do the other thing.
Here is how

bool Adafruit_Si4713::(begin addr, TwoWire *theWire)

The begin looks.

If you did

bool RadioDidRight = false;

setup()
{
RadioDidRight =  radio.begin;
If (RadioDidRight)
}

Now you got a thingy that will let any radio code know weather to run or not.

Look at the cpp Adafruit-Si4713-Library/Adafruit_Si4713.cpp at master · adafruit/Adafruit-Si4713-Library · GitHub
and h Adafruit-Si4713-Library/Adafruit_Si4713.h at master · adafruit/Adafruit-Si4713-Library · GitHub
to get an idea of what's going on.

Research.
Research.
Research.

Thank you I will read the links and take another look at this.

Just an FYI the issue with the code was a missing ";". The IF statement never closed so nothing after the statement was performed.