Password Code Goes Looping And Post Multiple Times To Serial Monitor

Hey There,

I Am Working On A Project Of A Wireless Morse Code Communication System (AM MODULATION)

And Get Stuck With Building A Basis Tranceiver Of An Arduino Uno, The Whole System Is Working Except 1 Part The Password Login System! i Need To Have The Password Setup so if The User Logon SuccesFully The PORTB Registers Goes On (For Transmitting), And If The User Type In The Wrong Password The Arduino Will Send A message Trough The Serial Monitor Like "::ERROR:: TRY ANOTHER PASSWORD ::ERROR::" So Only Authenticated Users Can Login Via Serial Monitor (and Probably Via my Own Website/CSHARP Application) in The Future, On This Way I Can Create Base Stations And Cover A Larger Planned Communication Network That Translates The Letters Into Morse Code Transmit It And Another Arduino Can Receive It Trough A Germanium Diode + Circuit That Put Electricity Out Of The Radio Signals Of The Diode And Feed It In An DigitalRead Pin So The Arduino Can Translate It Into Plain Text Again,

With That Said I Hope You Can help Me With The Password Protection Part Of It,

Tnx Already,

Best Regards Bradley Methorst (DragonicDefson)

PS (i Got The Actual Code From This Topic: Arduino + Wire = Morse Code AM Radio Beacon - Exhibition - Arduino Forum)

PS.2 (i Combined The 2 Posted Source Codes And Modified It With SOS Function An Default Call-sign-Function(1234))

And Here Is The Modified Upgraded Source Code:

long milliseconds_at_start = 0;
long milliseconds_at_the_end = 0;

const long length_of_transmitting_period = 8;

String password;

#define LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT 64

const int length_of_a_dot = LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int pause_after_transmitting_of_a_dot = LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int length_of_a_dash = 3 * LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int pause_after_transmitting_a_dash = LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int pause_between_words = 6 * LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;

void DOT (void); 
void DASH (void);
void PAUSE (void);

void start_transmitting ( int N_CYCLES );
void stop_transmitting ( int N_CYCLES );

#define ASM_INC( REGISTER ) asm volatile ( "inc %0" : "=r" ( REGISTER ) : "0" ( REGISTER ) )

char * Letters[] =
{
 ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",    // A-I
 ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",  // J-R
 "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."          // S-Z
};

char* Numbers[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."};

String sos[] =
{
  "DOT();", "DOT();", "DOT();", "DASH();", "DASH();",
  "DASH();","DOT();", "DOT();", "DOT();", "PAUSE();"
};

String default_call_sign[] =
{
  "DASH();", "DASH();", "DASH();", "DASH();", "DASH();",
  "DOT();", "DASH();", "DASH();", "DASH();", "DASH();",
  "DOT();", "DOT();", "DASH();", "DASH();", "DASH();",
  "DOT();", "DOT();", "DOT();", "DASH();", "DASH();" 
};

void setup()  
{

  Serial.begin(9600);
 
  DDRB = 0xFF;
 
  milliseconds_at_start = millis();
 
  DOT();
 
  milliseconds_at_the_end = millis();
 
  Serial.print( milliseconds_at_the_end - milliseconds_at_start );
  Serial.print( " " );
  Serial.print( "Frequency Transmitting On: " );
  Serial.print( ( length_of_a_dot + pause_after_transmitting_of_a_dot) * length_of_transmitting_period * 256 / (milliseconds_at_the_end - milliseconds_at_start) / 2 );
  Serial.print( "kHz" );
  Serial.println();
  Serial.println("Please Enter Your Password And Press Send");

  PORTB = 0x00;
}

void loop()  
{
  char Letter_Number;

  String add_on_modules;
  
  if (Serial.available())
  {
 
    if (password == "EARTH");
    {
        Serial.println("::SUCCES:: LOGGED ON EARTH STATION TRANSMITTER ::SUCCES::");

        DDRB = 0xFF;
    }
    
    if (password != "EARTH")
    {

        Serial.println("::ERROR:: TRY ANOTHER PASSWORD PLEASE ::ERROR::");
      
    }
    
    Letter_Number = Serial.read();

    add_on_modules = Serial.read();
      
    if (add_on_modules == "send sos")
    {
      TRANSMIT_SOS(); 
    }

    if (add_on_modules == "send call sign")
    {
      DEFAULT_CALL_SIGN();
    }
    
    if (Letter_Number >= 'a' && Letter_Number <= 'z')
    {
      transmit_sequence(Letters[Letter_Number - 'a']);
    }
  
    else if (Letter_Number >= 'A' && Letter_Number <= 'Z')
    {
      transmit_sequence(Letters[Letter_Number - 'A']);
    }
  
    else if (Letter_Number >= '0' && Letter_Number <= '9')
    {
      transmit_sequence(Numbers[Letter_Number - '0']);
    }
  
    else if (Letter_Number == ' ')
    {
      PAUSE();
    }
  }
}
  void transmit_sequence(char * sequence)
  {
    int i = 0;
      while (sequence[i] != NULL)
      {
        transmit_choice_dot_or_dash (sequence[i]);
        i++;
      }
  PAUSE();
}

void transmit_choice_dot_or_dash(char dot_or_dash)
{
  if (dot_or_dash == '.')
  {
    DOT();          
  }
 
  else
  {
    DASH();           
  }
}

void DOT (void)
{
  for ( int i = 0; i < length_of_a_dot; i++ )
  {
    start_transmitting (length_of_transmitting_period);
  }
 
  for ( int i = 0; i < pause_after_transmitting_of_a_dot; i++)
  {
    stop_transmitting (length_of_transmitting_period);
  }
}

void DASH (void)
{
  for ( int i = 0; i < length_of_a_dash; i++ )
  {
    start_transmitting (length_of_transmitting_period);
  }
  for( int i = 0; i < pause_after_transmitting_a_dash; i++ )
  {
    stop_transmitting (length_of_transmitting_period);
  }
}

void TRANSMIT_SOS (void)
{
  start_transmitting(sos);
}

void DEFAULT_CALL_SIGN (void)
{
  start_transmitting(default_call_sign); 
}

void PAUSE (void)
{
  for(int i = 0; i < pause_between_words; i++)
  {
    stop_transmitting (length_of_transmitting_period);
  }
}

void start_transmitting ( int N_CYCLES )
{
    unsigned int port_value;
    for ( int i = 0; i < N_CYCLES; i++ )
    {
        port_value = 0;
    do
    {
        PORTB = port_value;
        ASM_INC(port_value);
    }
    while(port_value < 255);
    }
}

void stop_transmitting ( int N_CYCLES )
{
    unsigned int port_value;
    PORTB = 0x00;
    for ( int i = 0; i < N_CYCLES; i++ )
    {
        port_value = 0;
    do
    {
        ASM_INC(port_value);
     
        asm volatile ("NOP");  
    }
    while(port_value < 255);
  }
}

I may be missing something, but I don't see a statement like Serial.read() etc. which is attempting to read the password which the user has entered into the variable password.

dragonicdefson:
Hey There,

I Am Working On A Project Of A Wireless Morse Code Communication System (AM MODULATION)

And Get Stuck With Building A Basis Tranceiver Of An Arduino Uno, The Whole System Is Working Except 1 Part The Password Login System! i Need To Have The Password Setup so if The User Logon SuccesFully The PORTB Registers Goes On (For Transmitting), And If The User Type In The Wrong Password The Arduino Will Send A message Trough The Serial Monitor Like "::ERROR:: TRY ANOTHER PASSWORD ::ERROR::" So Only Authenticated Users Can Login Via Serial Monitor (and Probably Via my Own Website/CSHARP Application) in The Future, On This Way I Can Create Base Stations And Cover A Larger Planned Communication Network That Translates The Letters Into Morse Code Transmit It And Another Arduino Can Receive It Trough A Germanium Diode + Circuit That Put Electricity Out Of The Radio Signals Of The Diode And Feed It In An DigitalRead Pin So The Arduino Can Translate It Into Plain Text Again,

With That Said I Hope You Can help Me With The Password Protection Part Of It,

Tnx Already,

Best Regards Bradley Methorst (DragonicDefson)

PS (i Got The Actual Code From This Topic: Arduino + Wire = Morse Code AM Radio Beacon - Exhibition - Arduino Forum)

PS.2 (i Combined The 2 Posted Source Codes And Modified It With SOS Function An Default Call-sign-Function(1234))

And Here Is The Modified Upgraded Source Code:

long milliseconds_at_start = 0;

long milliseconds_at_the_end = 0;

const long length_of_transmitting_period = 8;

String password;

#define LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT 64

const int length_of_a_dot = LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int pause_after_transmitting_of_a_dot = LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int length_of_a_dash = 3 * LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int pause_after_transmitting_a_dash = LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;
const int pause_between_words = 6 * LENGTH_OF_TRANSMITTING_PERIOD_OF_A_DOT;

void DOT (void);
void DASH (void);
void PAUSE (void);

void start_transmitting ( int N_CYCLES );
void stop_transmitting ( int N_CYCLES );

#define ASM_INC( REGISTER ) asm volatile ( "inc %0" : "=r" ( REGISTER ) : "0" ( REGISTER ) )

char * Letters[] =
{
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",    // A-I
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",  // J-R
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."          // S-Z
};

char* Numbers[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."};

String sos[] =
{
  "DOT();", "DOT();", "DOT();", "DASH();", "DASH();",
  "DASH();","DOT();", "DOT();", "DOT();", "PAUSE();"
};

String default_call_sign[] =
{
  "DASH();", "DASH();", "DASH();", "DASH();", "DASH();",
  "DOT();", "DASH();", "DASH();", "DASH();", "DASH();",
  "DOT();", "DOT();", "DASH();", "DASH();", "DASH();",
  "DOT();", "DOT();", "DOT();", "DASH();", "DASH();"
};

void setup() 
{

Serial.begin(9600);

DDRB = 0xFF;

milliseconds_at_start = millis();

DOT();

milliseconds_at_the_end = millis();

Serial.print( milliseconds_at_the_end - milliseconds_at_start );
  Serial.print( " " );
  Serial.print( "Frequency Transmitting On: " );
  Serial.print( ( length_of_a_dot + pause_after_transmitting_of_a_dot) * length_of_transmitting_period * 256 / (milliseconds_at_the_end - milliseconds_at_start) / 2 );
  Serial.print( "kHz" );
  Serial.println();
  Serial.println("Please Enter Your Password And Press Send");

PORTB = 0x00;
}

void loop() 
{
  char Letter_Number;

String add_on_modules;
 
  if (Serial.available())
  {

if (password == "EARTH");
    {
        Serial.println("::SUCCES:: LOGGED ON EARTH STATION TRANSMITTER ::SUCCES::");

DDRB = 0xFF;
    }
   
    if (password != "EARTH")
    {

Serial.println("::ERROR:: TRY ANOTHER PASSWORD PLEASE ::ERROR::");
     
    }
   
    Letter_Number = Serial.read();

add_on_modules = Serial.read();
     
    if (add_on_modules == "send sos")
    {
      TRANSMIT_SOS();
    }

if (add_on_modules == "send call sign")
    {
      DEFAULT_CALL_SIGN();
    }
   
    if (Letter_Number >= 'a' && Letter_Number <= 'z')
    {
      transmit_sequence(Letters[Letter_Number - 'a']);
    }
 
    else if (Letter_Number >= 'A' && Letter_Number <= 'Z')
    {
      transmit_sequence(Letters[Letter_Number - 'A']);
    }
 
    else if (Letter_Number >= '0' && Letter_Number <= '9')
    {
      transmit_sequence(Numbers[Letter_Number - '0']);
    }
 
    else if (Letter_Number == ' ')
    {
      PAUSE();
    }
  }
}
  void transmit_sequence(char * sequence)
  {
    int i = 0;
      while (sequence[i] != NULL)
      {
        transmit_choice_dot_or_dash (sequence[i]);
        i++;
      }
  PAUSE();
}

void transmit_choice_dot_or_dash(char dot_or_dash)
{
  if (dot_or_dash == '.')
  {
    DOT();         
  }

else
  {
    DASH();         
  }
}

void DOT (void)
{
  for ( int i = 0; i < length_of_a_dot; i++ )
  {
    start_transmitting (length_of_transmitting_period);
  }

for ( int i = 0; i < pause_after_transmitting_of_a_dot; i++)
  {
    stop_transmitting (length_of_transmitting_period);
  }
}

void DASH (void)
{
  for ( int i = 0; i < length_of_a_dash; i++ )
  {
    start_transmitting (length_of_transmitting_period);
  }
  for( int i = 0; i < pause_after_transmitting_a_dash; i++ )
  {
    stop_transmitting (length_of_transmitting_period);
  }
}

void TRANSMIT_SOS (void)
{
  start_transmitting(sos);
}

void DEFAULT_CALL_SIGN (void)
{
  start_transmitting(default_call_sign);
}

void PAUSE (void)
{
  for(int i = 0; i < pause_between_words; i++)
  {
    stop_transmitting (length_of_transmitting_period);
  }
}

void start_transmitting ( int N_CYCLES )
{
    unsigned int port_value;
    for ( int i = 0; i < N_CYCLES; i++ )
    {
        port_value = 0;
    do
    {
        PORTB = port_value;
        ASM_INC(port_value);
    }
    while(port_value < 255);
    }
}

void stop_transmitting ( int N_CYCLES )
{
    unsigned int port_value;
    PORTB = 0x00;
    for ( int i = 0; i < N_CYCLES; i++ )
    {
        port_value = 0;
    do
    {
        ASM_INC(port_value);
   
        asm volatile ("NOP"); 
    }
    while(port_value < 255);
  }
}

What the Hell is wrong with your shift key? :o

Hello There, Sorry For My Late Reply,

You Are Right About The Statement Serial.read(); I Got It In The Code But I Have Changed The Code Soooo Much And Every Attempt To Make It Working Fails, With Or Without Serial.Read(); The Serial.read(); Statement belongs Between if (Serial.available()) And IF(Password == "EARTH"), And I Have Try This By:

password = Serial.read(); But It Fails Every Time! A few Minutes Ago I Get The Conclusion The Serial.read(); Statement Only Accepts Integers (INTS), And I need Or A 6 Digit Number Code, Or A String As Password, That Are The 2 Only Options,

I Hope You Can Help Me!

And LOL Yeah I Like To Write Words With A Big Letter At The Beginning XD

Best Regards,
Bradley Methorst (DragonicDefson)

I Like To Write Words With A Big Letter At The Beginning

I suggest that you stop doing it in this forum if you want help.

password = Serial.read();Reads one byte, not an int. The byte may be an actual number or a number representing a character.

Have a look at Serial input basics - updated

Ah okey, sorry for that,

i have looked in the that part of the forum, but i dont know how to fix this and make this on the way the code should suppose to be,

help is very appreciated, i thought it was as easy by adding just an if/else statement, but now i think its much difficult to do,

i hope there is a good solution for this and i hope you can help me,

there must be a Solution right?

Best Regards,

Bradley Methorst (DragonicDefson)