COMP600 Spring Lab#2
COMP600 Spring Lab#2
Objectives:
To use Arduino boards, basic components, IDE, and programming language in basic
implementation to send output signals.
Tasks:
1. Work individually to perform all the tasks.
2. Please work individually and navigate to https://www.tinkercad.com/ and sign up for a free
account.
3. Go to the dashboard and choose “Circuits” then create a new circuit
Page 1 of 7
COMP 600
Emerging Wireless Technologies
Page 2 of 7
COMP 600
Emerging Wireless Technologies
5. In the “Code” area, choose text format and write the following code for Arduino
void setup()
{
pinMode(7, OUTPUT);
}
void loop()
{
digitalWrite(7, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(7, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
7. and study carefully the previous steps, then proceed with the next steps.
8. Add another LED (to be connected to different digital pin) and modify the code so both LEDs
will blink at the same time- relatively- and increase the blinking speed. (Copy and paste your
modified code below, Also take a snapshot of your modified circuit and paste it below in the
box)
Put your modified code here:
// C++ code
//
void setup()
{
pinMode(7, INPUT);
pinMode(8,INPUT);
Page 3 of 7
COMP 600
Emerging Wireless Technologies
void loop()
{
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(100);//Wait for 100 millisecond(s)
digitalWrite(7,LOW);
digitalWrite(8,LOW);
delay(100);// Wait for 100 millisecond(s)
Page 4 of 7
COMP 600
Emerging Wireless Technologies
9. Discussion Questions:
a) What is the function in terms of programming? Explain with more details and give
illustration example.
b) What are the benefits of setup() & loop() functions? Explain with more details.
a) It is an organized code that can be reused to perform different tasks (multiple times). It is
designed to take specific input and gives us desired output (called arguments). A function
contains a Name, Input Parameters, Body, Return Statement, and Function Call.
Name- It has a unique name that identifies with the program. (Should be descriptive and
indicate the purpose or action performed by function).
Input Parameters- These are called arguments or variables. These allow a person to pass
the value and can accept zero or more input parameters.
Body- This contains all the instructions or code that would define what exactly a function
does.
Return Statement- A function has an output which we call it a return value. It is optional.
Function Call- One needs to call a function by its name or by passing an argument to
execute it.
Example-
#include <iostream>
// Function declaration
void printHelloWorld();
int main() {
// Function call
printHelloWorld();
return 0;
}
// Function definition
void printHelloWorld() {
std::cout << "Hello, World!" << std::endl;
}
Page 5 of 7
COMP 600
Emerging Wireless Technologies
Loop() – It is executed repeatedly after the setup(). It is the main part of Arduino.
The main benefits of the loop() function are-
1. Continuous Execution – It runs in an infinite loop. It allows the program to perform
the tasks continuously.
2. Event-Driven Programming – One can write code that responds to various events or
conditions. For instance- reading data, responding to button presses.
3. Real-Time Control- One has the control over timing and execution of the speed of the
code. By using the functions delay(), millis() and micros().
10. Conclusion:
Page 6 of 7
COMP 600
Emerging Wireless Technologies
Submission Guidelines:
Go to D2L and answer the lab related question during the lab duration as per your
schedule.
Due Date: Check D2L. (Please submit the labs on time since no extensions; Zero
Tolerance).
Submission Method: Dropbox folder ONLY for this file.
Page 7 of 7