Создайте проект.Добавте макетну плату та плату ардуіно.Написать програму дл вмикання світлофора,який вмикається кнопкою и под час переключения светодиодов виводится повідомлення на LCD дисплей
Ответы
Відповідь:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
const int buttonPin = 8; // the number of the pushbutton pin
const int redLed = 9; // the number of the red LED pin
const int yellowLed = 10; // the number of the yellow LED pin
const int greenLed = 6; // the number of the green LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
pinMode(redLed, OUTPUT); // initialize the red LED pin as an output
pinMode(yellowLed, OUTPUT); // initialize the yellow LED pin as an output
pinMode(greenLed, OUTPUT); // initialize the green LED pin as an output
lcd.print("Traffic Light");
delay(1000);
lcd.clear();
lcd.print("Press the button");
}
void loop() {
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
if (buttonState == HIGH) {
digitalWrite(redLed, HIGH); // turn red LED on
lcd.clear();
lcd.print("Red Light On");
delay(2000);
digitalWrite(redLed, LOW); // turn red LED off
digitalWrite(yellowLed, HIGH); // turn yellow LED on
lcd.clear();
lcd.print("Yellow Light On");
delay(1000);
digitalWrite(yellowLed, LOW); // turn yellow LED off
digitalWrite(greenLed, HIGH); // turn green LED on
lcd.clear();
lcd.print("Green Light On");
delay(2000);
digitalWrite(greenLed, LOW); // turn green LED off
}
}
Пояснення: