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?
#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