Professional Documents
Culture Documents
MP01 Assignment
MP01 Assignment
1.Objective: .................................................................................................................................................. 1
2. Introduction:............................................................................................................................................. 1
1. LED blinking: ...................................................................................................................................... 2
2. Delay Subroutine............................................................................................................................... 2
3. Serial communication: ...................................................................................................................... 2
3.Procedures:................................................................................................................................................ 2
a) Procedure of the LED Blinking........................................................................................................... 2
b) Procedure for the Delay subroutine. ................................................................................................ 2
c) Procedure for the serial Monitor. ..................................................................................................... 2
4.Code: .......................................................................................................................................................... 3
I. Code for the LED blinking with Boolean function and Random Delay.............................................. 3
II. Code for the serial communication using random delay .................................................................. 3
III. Code for the Random delay from the serial monitor.................................................................... 4
5.Results: ...................................................................................................................................................... 5
1. Random Delay ................................................................................................................................... 5
2. Random Delay with showing the Timestamps.................................................................................. 6
3. Difference Between the time shown and generating random delay ............................................... 6
4. Serial Monitor delay using random numbers from the input ........................................................... 7
6.Discussions: ............................................................................................................................................... 7
1.Objective:
The objective of this report is to get familiarity with the basics of the Arduino programming and the
structure of the programming in the Arduino.
2. Introduction:
This report is based on the understanding of the basic codes of the Arduino Mega. These concepts are
including but not limited to the blinking of LED, delay subroutine and serial communication.
1. LED blinking:
The LED blinking is done with the various methods, these are the simple delay creations, where the
code gets a lot lengthy, afterwards the code efficiency is increased via Boolean functions of
inequality.
2. Delay Subroutine:
The delay subroutine is made using different algorithms for the creation of the required delays in
seconds in milliseconds.
3. Serial communication:
There is mentioned a bit in detailed about the numerous method for having the serial
communication, where a light has been shed on the delay computation using the graph of the serial
monitor.
3.Procedures:
As we have seen there are various things, that have been discussed in the report, let’s have a look at
these things a bit in detail, given below.
4.Code:
I. Code for the LED blinking with Boolean function and Random Delay
void setup() {
// Configure the LED Pin for OUTPUT
pinMode(ledPin, OUTPUT);
randomSeed(analogRead(0));
}
void loop() {
// Toggle the LED State
ToggleLED(ledPin);
// Wait the delay time until the next loop
delay(random(10000, 20000));
}
void setup() {
// Initialize a Serial Interface at 9600 baud
Serial.begin(9600);
// Wait for the interface to fully initialize
while(!Serial) {
;
}
}
void loop() {
// Toggle the LED State
ToggleLED(ledPin);
// Determine the delay time
int delayTime = random(200, 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);
}
III. Code for the Random delay from the serial monitor
void setup() {
// Initialize a Serial Interface at 9600 baud
Serial.begin(9600);
// Wait for the interface to fully initialize
while(!Serial) {
;
}
}
void loop() {
// Toggle the LED State
ToggleLED(ledPin);
// Wait the delay time until the next loop
int delayTime=1000;
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 Int
delayTime = Serial.readString().toInt();6
// Confirm new data received by printing it back to the Serial Monitor
Serial.print("Received new delay time: ");
Serial.println(delayTime);
}
}
5.Results:
1. Random Delay
2. Random Delay with showing the Timestamps
6.Discussions:
From the first graph we can see that the delay is of the random numbers, and these number are
generated using the Random (Min, Max) command. The delay coming from this command is then shown
on the serial monitor.
In the second Graph we can see that the delay is likewise, but shown it with the timestamp, which is
clearly shown in the serial monitor.
In the third graph we can see that there exist a difference between the delay come from the random
numbers and the delay shown from the timestamps, this delay is drawn with the help of the serial
plotter.
In the final graph we can see that the delay is generated but based on the input. Written on the serial
monitor, this delay is varying with respect to the input number one enters.