Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please show the code and everything Complete the following using an Arduino Mega and the Arduino IDE. Make sure to pay attention to Section 6,

please show the code and everything image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Complete the following using an Arduino Mega and the Arduino IDE. Make sure to pay attention to Section 6, DOCUMENTING YOUR RESULTS for details of what information to capture as you execute this project. 1. CONNECTING TO THE ARDUINO 1.1. Launch the Arduino IDE by searching for "Arduino" in the start menu. 1.2. Connect the Arduino using the provided USB cable to any available USB port on your computer. 1.3. Use the menu at the top of the Arduino IDE to select "Tools"->"Board", and select "Arduino/Genuino Mega or Mega 2560". OOD 1.4. Similarly, select "Tools"->"Port", and select the available COM port for your board. OOD 2. WRITING YOUR FIRST PROGRAM 2.1. Copy the following code to the Arduino IDE: // Select the pin number of the LED to control const int ledPin = LED_BUILTIN; // This will hold the current state of the LED bool ledState = false; // Time to delay in milliseconds int delayTime = 1000; void setup() { // Configure the LED Pin for OUTPUT pinMode(ledPin, OUTPUT); void loop() { // Toggle the state of the LED in memory ledState = HIGH; // Write the new value for the LED to the pin digitalWrite(ledPin, ledState); 17 Wait the delay time until the next loop delay(delayTime); 1/ Toggle the state of the LED in memory ledState - LOW; // Write the new value for the LED to the pin digitalWrite(ledPin, ledState); // Wait the delay time until the next loop delay(delayTime); 2.2. Using the Upload button , deploy this program to the Arduino. 2.3. Verify that the LED next to Digital Pin 13 is blinking at 1 second intervals. 3. MODIFYING YOUR PROGRAM 3.1. Creating a "Blink" function 3.1.1. To make your program more adaptable, let's create a function called "ToggleLED" that will take one argument, a pin number. void ToggleLED(int pinNumber) { // Toggle the state of the LED in memory ledState - IledState; // Write the new value for the LED to the pin digitalWrite(ledPin, ledState); 3.1.2. Modify your loop routine to call this function instead of the previous code. Note that by using the Boolean NOT operator "?", we are able to condense our original code to the following: void loop() { // Toggle the LED State ToggleLED(ledPin); 1/ wait the delay time until the next loop delay(delayTime); 3.2. Changing the delay time 3.2.1. Now that we have a function that simplifies the toggling function, let's take it a step further and adjust our delay time. Modify your program to return a random delay time between 200 and 2000 milliseconds using the following information from the Arduino language reference to assist you. random() 4. ADDING A SERIAL DIAGNOSTICS INTERFACE 4.1. Adding a random delay can be visualized, but let's take this a step further and keep a log of the random numbers that are generated by this function. To do so, we'll implement a Serial interface to the host computer. 4.2. First, add the following to your setup routine immediately after configuring the led Pin's mode: // Initialize a Serial Interface at 9600 baud Serial.begin(9600); // Wait for the interface to fully initialize while(Serial) { 4.3. Next, modify your loop routine to match the following: void loop() { // Toggle the LED State ToggleLED(ledPin); // Determine the delay time int delayTime - random( 208, 2000); // Print the delay time to the Serial Monitor Serial.print("Delay Time: "); Serial.println(delayTime); // wait the delay time until the next loop delay(delayTime); 4.4. Deploy your code, then open the serial monitor by navigating in the menu to "Tools"->"Serial Monitor" 4.4.1. Observe the values printed to the monitor. Document your results 4.4.2. Enable Timestamps using the checkbox; see if the time between timestamps matches the anticipated delay time. NOTE: There will be a small error due to operational overhead. Document this error. 4.4.3. Close the Serial Monitor, and open the Serial Plotter using the menu to navigate to "Tools"->"Serial Plotter" 4.4.4. You should see a plot of delay time relative to sample index (n-th sample). Document your results. ES 5. SERIALLY CONTROLLED DELAY 5.1. Now that we have a serial interface set up from the host machine to the Arduino, we will modify our program one more time to use a fixed delay again, but receive the delay as a programmed value from the serial interface. 5.2. Update your loop function to: void loop() { // Toggle the LED State ToggleLED(ledPin); 1/ Wait the delay time until the next loop delay(delayTime); // Check if serial data is available if (Serial.available() > 0) { // If it is, read until a new line char is received, then convert to Intl delayTime - Serial.readString().toInt(); // Confirm new data received by printing it back to the Serial Monitor Serial.print("Received new delay time: "); Serial.println(delayTime); 5.3. Upload your code and test it using a few different delay times. Verify that the frequency of LED blink varies when new commands are sent, and that the serial monitor responds accordingly. Document your results. COM Received new delay time 100 Received new delay time 50 Received new delay time 500 6. DOCUMENTING YOUR RESULTS 6.1. Submit a report to Canvas detailing your findings. This report should meet the format requirements outlined in Lecture 01, and should include, at a minimum, the following: 6.1.1. Code from the completion of each major section, e.g. Section 3. 6.1.1.1. This project should have 4 separate "sketches" submitted as part of the report. 6.1.2. Screenshots of any serial monitor windows, graphs, etc 6.1.3. Results of any calculations performed, e.g. difference between serial monitor timestamp and stated delay Complete the following using an Arduino Mega and the Arduino IDE. Make sure to pay attention to Section 6, DOCUMENTING YOUR RESULTS for details of what information to capture as you execute this project. 1. CONNECTING TO THE ARDUINO 1.1. Launch the Arduino IDE by searching for "Arduino" in the start menu. 1.2. Connect the Arduino using the provided USB cable to any available USB port on your computer. 1.3. Use the menu at the top of the Arduino IDE to select "Tools"->"Board", and select "Arduino/Genuino Mega or Mega 2560". OOD 1.4. Similarly, select "Tools"->"Port", and select the available COM port for your board. OOD 2. WRITING YOUR FIRST PROGRAM 2.1. Copy the following code to the Arduino IDE: // Select the pin number of the LED to control const int ledPin = LED_BUILTIN; // This will hold the current state of the LED bool ledState = false; // Time to delay in milliseconds int delayTime = 1000; void setup() { // Configure the LED Pin for OUTPUT pinMode(ledPin, OUTPUT); void loop() { // Toggle the state of the LED in memory ledState = HIGH; // Write the new value for the LED to the pin digitalWrite(ledPin, ledState); 17 Wait the delay time until the next loop delay(delayTime); 1/ Toggle the state of the LED in memory ledState - LOW; // Write the new value for the LED to the pin digitalWrite(ledPin, ledState); // Wait the delay time until the next loop delay(delayTime); 2.2. Using the Upload button , deploy this program to the Arduino. 2.3. Verify that the LED next to Digital Pin 13 is blinking at 1 second intervals. 3. MODIFYING YOUR PROGRAM 3.1. Creating a "Blink" function 3.1.1. To make your program more adaptable, let's create a function called "ToggleLED" that will take one argument, a pin number. void ToggleLED(int pinNumber) { // Toggle the state of the LED in memory ledState - IledState; // Write the new value for the LED to the pin digitalWrite(ledPin, ledState); 3.1.2. Modify your loop routine to call this function instead of the previous code. Note that by using the Boolean NOT operator "?", we are able to condense our original code to the following: void loop() { // Toggle the LED State ToggleLED(ledPin); 1/ wait the delay time until the next loop delay(delayTime); 3.2. Changing the delay time 3.2.1. Now that we have a function that simplifies the toggling function, let's take it a step further and adjust our delay time. Modify your program to return a random delay time between 200 and 2000 milliseconds using the following information from the Arduino language reference to assist you. random() 4. ADDING A SERIAL DIAGNOSTICS INTERFACE 4.1. Adding a random delay can be visualized, but let's take this a step further and keep a log of the random numbers that are generated by this function. To do so, we'll implement a Serial interface to the host computer. 4.2. First, add the following to your setup routine immediately after configuring the led Pin's mode: // Initialize a Serial Interface at 9600 baud Serial.begin(9600); // Wait for the interface to fully initialize while(Serial) { 4.3. Next, modify your loop routine to match the following: void loop() { // Toggle the LED State ToggleLED(ledPin); // Determine the delay time int delayTime - random( 208, 2000); // Print the delay time to the Serial Monitor Serial.print("Delay Time: "); Serial.println(delayTime); // wait the delay time until the next loop delay(delayTime); 4.4. Deploy your code, then open the serial monitor by navigating in the menu to "Tools"->"Serial Monitor" 4.4.1. Observe the values printed to the monitor. Document your results 4.4.2. Enable Timestamps using the checkbox; see if the time between timestamps matches the anticipated delay time. NOTE: There will be a small error due to operational overhead. Document this error. 4.4.3. Close the Serial Monitor, and open the Serial Plotter using the menu to navigate to "Tools"->"Serial Plotter" 4.4.4. You should see a plot of delay time relative to sample index (n-th sample). Document your results. ES 5. SERIALLY CONTROLLED DELAY 5.1. Now that we have a serial interface set up from the host machine to the Arduino, we will modify our program one more time to use a fixed delay again, but receive the delay as a programmed value from the serial interface. 5.2. Update your loop function to: void loop() { // Toggle the LED State ToggleLED(ledPin); 1/ Wait the delay time until the next loop delay(delayTime); // Check if serial data is available if (Serial.available() > 0) { // If it is, read until a new line char is received, then convert to Intl delayTime - Serial.readString().toInt(); // Confirm new data received by printing it back to the Serial Monitor Serial.print("Received new delay time: "); Serial.println(delayTime); 5.3. Upload your code and test it using a few different delay times. Verify that the frequency of LED blink varies when new commands are sent, and that the serial monitor responds accordingly. Document your results. COM Received new delay time 100 Received new delay time 50 Received new delay time 500 6. DOCUMENTING YOUR RESULTS 6.1. Submit a report to Canvas detailing your findings. This report should meet the format requirements outlined in Lecture 01, and should include, at a minimum, the following: 6.1.1. Code from the completion of each major section, e.g. Section 3. 6.1.1.1. This project should have 4 separate "sketches" submitted as part of the report. 6.1.2. Screenshots of any serial monitor windows, graphs, etc 6.1.3. Results of any calculations performed, e.g. difference between serial monitor timestamp and stated delay

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

ISBN: 0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

2. Write two or three of your greatest weaknesses.

Answered: 1 week ago