Vous êtes sur la page 1sur 7

Joshi yogesh

roll no 111060752027

Assignment 3
1. Develop an Arduino application that will blink the three types of LEDs - red, yellow and green to create a pattern. There should be a 300ms delay between the each LED blinking. The pattern is Red - Yellow - Green - Yellow.

void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); }

void loop() { digitalWrite(13, HIGH); // set the LED on delay(300); // wait for a second

digitalWrite(13, LOW); // set the LED off delay(300); digitalWrite(12, HIGH); // set the LED on delay(300); // wait for a second

digitalWrite(12, LOW); // set the LED off delay(300); // wait for a second digitalWrite(11, HIGH); // set the LED on delay(300); // wait for a second

Joshi yogesh digitalWrite(11, LOW); // set the LED off delay(300); digitalWrite(12, HIGH); // set the LED on delay(300); // wait for a second

roll no 111060752027

digitalWrite(12, LOW); // set the LED off delay(300); // wait for a second }

Joshi yogesh

roll no 111060752027

2. Develop an Arduino application that will display a message on the LCD display. Scroll the message in the left direction until the LCD screen is blank and after a delay of 200ms scroll back the reversed message on the LCD display. #include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("ASSIGNMENT -3"); setcursor(o,1); lcd.print("EMBEDDED SYSTEMS"); delay(200); }

Joshi yogesh

roll no 111060752027

void loop() { // scroll 13 positions (string length) to the left // to move it offscreen left: for (int positionCounter = 0; positionCounter < 12; positionCounter++) { // scroll one position left: lcd.scrollDisplayLeft(); // wait a bit: delay(200); }

// scroll 29 positions (string length + display length) to the right // to move it offscreen right: for (int positionCounter = 0; positionCounter < 29; positionCounter++) { // scroll one position right: lcd.scrollDisplayRight(); // wait a bit: delay(200); }

// scroll 16 positions (display length + string length) to the left // to move it back to center:

Joshi yogesh for (int positionCounter = 0; positionCounter < 16; positionCounter++) { // scroll one position left: lcd.scrollDisplayLeft(); // wait a bit: delay(200); }

roll no 111060752027

// delay at the end of the full loop: delay(200); }

Joshi yogesh

roll no 111060752027

3. Develop an Arduino application that uses a potentiometer to control the contrast of the LCD screen. Use an LED to verify if your code is working properly i.e. when the screen is dark the LED should glow and vice-versa. #include <LiquidCrystal.h> int ledPin = 9; // LED connected to digital pin 9 int analogPin = A0; // potentiometer connected to analog pin 3 int val = 0; // variable to store the read value LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() { pinMode(9, OUTPUT); // sets the pin as output // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("joshi"); } void loop() {

Joshi yogesh

roll no 111060752027

val = analogRead(analogPin); // read the input pin analogWrite(9, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); }

Vous aimerez peut-être aussi