# \#define debug true

**URL:** <https://forum.arduino.cc/t/define-debug-true/525248>\
**Category:** Programming\
**Created:** [May 10, 2018, 5:33am UTC](https://forum.arduino.cc/t/define-debug-true/525248 "2018-05-10T05:33:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edgarsteven](https://avatars.discourse-cdn.com/v4/letter/e/dc4da7/32.png) [@Edgarsteven](https://forum.arduino.cc/u/Edgarsteven)\
**Post date:** [May 10, 2018, 5:33am UTC](https://forum.arduino.cc/t/define-debug-true/525248/1 "2018-05-10T05:33:29Z")

</div>

Hey I really need your help guys. I'm trying to learn this code. Here is my first question of many questions.  
What does... #define debug true.. do?

```cpp
#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, NEGATIVE);

#define I2C_ADDR 0x27  // Define the address of the serial communication display 
#define LED_OFF 0
#define LED_ON 1

#define debug true

int ledPin = 13;          //The pin, your LED is connected to.
int speakerPin = 9;      //The pin, your buzzer or speaker is connected to.
int pitch1 = 140;
int pitch2 = 140;
int dot = 50;
int dash = 3 * dot;

String morseATable[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",  // A-G
                        "....", "..", ".---", "_._", ".-..", "--", "-.",    // H-N
                        "---", ".--.", "--.-", ".-.", "...", "-", "..-",    // O-U
                        "...-", ".--", "-..-", "-.--", "--.."              // V-Z
                      };

String morseNTable[] = { "-----", ".----", "..---", "...--", "....-",      // 0-4
                        ".....", "-....", "--...", "---..", "----."        // 5-9
                      };

void setup()
{
  lcd.begin(16, 2);              //Initialize the display
  lcd.setBacklight(LED_OFF);
  lcd.cursor();
  pinMode(ledPin, OUTPUT);
  pinMode(speakerPin, OUTPUT);
  Serial.begin(9600);
  if (debug)
    Serial.println("\nSTART");
}

void loop ()
{
  if (true) {

    convert2Morse(Serial.readString());
  }
  else if (false)
  {
    lcd.print("no u.");
  }
}

void convert2Morse(String message)
{
  for (int pos = 0; pos < message.length(); pos++)
  {
    if (debug)
    {
      Serial.print(message.charAt(pos));
      Serial.print("  ");
      lcd.print(message.charAt(pos));
      lcd.print(" ");

    }
    if ((message.charAt(pos) >= 97) && (message.charAt(pos) <= 122))
      morseLED(morseATable[message.charAt(pos) - 97]);
    if ((message.charAt(pos) >= 48) && (message.charAt(pos) <= 57))
      morseLED(morseNTable[message[pos] - 48]);
    if (message.charAt(pos) == 32)
      morseLED("      ");
    if (debug)
      Serial.println();

    delay(1000);
    lcd.clear();
  }
}

void morseLED(String sequence)
{
  for (int pos = 0; pos < sequence.length(); pos++)
    flashLED(sequence.charAt(pos));
  delay(2 * dot);
}

void flashLED(char dotOrDash)
{
  if (debug)
    Serial.print(dotOrDash);
  lcd.print(dotOrDash);

  if (dotOrDash == 46)
  {
    digitalWrite(ledPin, HIGH);
    tone (speakerPin, pitch1);
    delay(dot);
    digitalWrite(ledPin, LOW);
    noTone(speakerPin);
    delay(dot);
  }
  else if (dotOrDash == 45)
  {
    digitalWrite(ledPin, HIGH);
    tone (speakerPin, pitch2);
    delay(dash);
    digitalWrite(ledPin, LOW);
    noTone(speakerPin);
    delay(dot);
  }
  else if (dotOrDash == 32)
    delay(dot);
}

```

I will try to learn the other stuffs in the code

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [May 10, 2018, 6:29am UTC](https://forum.arduino.cc/t/define-debug-true/525248/2 "2018-05-10T06:29:34Z")

</div>

> What does... #define debug true.. do?

```arduino
  if (debug)
    Serial.println("\nSTART");

```

Printing of "START" will only occur when debug has been set to true, and there are other sections of code that will only be executed if debug is true

When the program is tested and working set debug to false for the final version of the program

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:10pm UTC](https://forum.arduino.cc/t/define-debug-true/525248/3 "2021-05-05T23:10:56Z")

</div>

Closed on May 5, 2021, 11:10pm UTC


