You are on page 1of 3

MPI LAB

LAB 8
Handling Arduino

Name : Burhan Ahmed Satti


Enrollment No. : 01-134172-065
Class : BSCS 4-A
Subject : MPI Lab
Lab Assistant : Muhammad Atif

Objectives
•Introduction to Arduino
•Introduction to basic architecture of Arduino
•Learning the use of Arduino IDE.

Tools Used
•Arduino IDE
BSCS 4-A Burhan Ahmed Satti 01-134172-065

Task No. 8.1


Write a program to toggle pin 15, 16 & 17 one by one, keep a delay of one second between
them.
Solution
int led= 13;
int pushButton = 2;
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(pushButton, INPUT);
}
void loop()
{
digitalWrite(led, HIGH);
int buttonState = digitalRead(led);
Serial.println(buttonState);
digitalWrite(led, LOW);
int buttonState = digitalRead(led);
Serial.println(buttonState);
}
}

Conclusion
The wave has on time for 37.5 percent of the time

MPI Lab Page 2 of 3


BSCS 4-A Burhan Ahmed Satti 01-134172-065

Task No. 8.2


Write a program to monitor the status of input pins and change the state of output pins accord-
ingly.
Solution
int led1= 40;
int led2= 41;
int led3= 42;
int pushButton = 20; int pushButton2 = 22; int pushButton3 = 24;

void setup() {
Serial.begin(9600);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(pushButton1, INPUT);
pinMode(pushButton2, INPUT);
pinMode(pushButton3, INPUT); }
void loop() {
int buttonState = digitalRead(led);
Serial.println(buttonState);
int buttonState = digitalRead(led2);
Serial.println(buttonState2);
int buttonState = digitalRead(led3);
Serial.println(buttonState3);
}
}

Conclusion
LEDs are blinking

MPI Lab Page 3 of 3

You might also like