Answered You can hire a professional tutor to get the answer.

QUESTION

this is for CT262 Week 6 at Grantham. I have to write this Arduino sketch that does the following: A system that requests an input from the user in...

this is for CT262 Week 6 at Grantham. I have to write this Arduino sketch that does the following:

A system that requests an input from the user in the form of a username or an ID (i.e. jd626) and then checks to verify that against stored username or ID. The system should display "Please enter your username or ID: " in the serial monitor when you run the code.

1) If the data entered by the user matches the stored data then the system results in an authorized access (simulating an authorized entry) by echoing "Hello <your full name>" in the serial monitor and turning ON the green LED on the circuit.

2) If the data entered does not match the stored data then the system results in unauthorized access (simulating an unauthorized entry) by echoing "Invalid Username" in the serial monitor and turning ON the red LED on the circuit. Make a note that the original prompt will be displayed to repeat the process in the serial monitor.

I have a sketch written but it allows any name access. Please help me to understand what I need to change to make this sketch work properly:

const int RED=11;

const int GREEN=10;

String login;

void setup() 

{

 Serial.begin(9600);

 pinMode(RED, OUTPUT);

 pinMode(GREEN, OUTPUT);

}

void loop() 

{

 Serial.println("Please enter your username or ID: ");

 while (Serial.available()==0);

 login = Serial.readString();

 if (login = "james")

  {

   Serial.println("Hello James!");

   digitalWrite(GREEN, HIGH);

   digitalWrite(RED, LOW);

   delay(5000);

  }

 else if (login != "james")

  {

   Serial.println("Invalid username");

   digitalWrite(GREEN, LOW);

   digitalWrite(RED, HIGH);

   Serial.flush();

  }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question