Код для поиска

Lesson 9: Using Switch and Push Buttons with Arduino

Lesson 9: Using Switch and Push Buttons with Arduino

We learn how a switch turns on and off a bulb. We learn how to use a push button or switch with and without a resistor with Arduino. Using INPUT_PULLUP has been explained.

541-Lesson 9: Using Switch and Push Buttons with Arduino
Язык: C++
/*
 * S01-09 Push Button
 * Written by Ahmad Shamshiri

Please watch video instructions here https://youtu.be/3K996EfPiXM
This code is available at http://robojax.com/course1/?vid=lecture09

with over 100 lectures free on YouTube. Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339
 * Written by Ahmad Shamshiri for Robojax, robojax.com http://youtube.com/robojaxTV
 * on Dec 24, 2018 in Ajax, Ontario, Canada
 *
 */

void setup() {
  pinMode(2, INPUT);// define pin 2 as input
  Serial.begin(9600);// initialize the serial monitor
                     // with 9600 baud
  Serial.println("Push button Test");
  pinMode(8, OUTPUT);

}

void loop() {
		//Robojax Step-by-Step Arduino Course http://robojax.com/L/?id=338
 int pushButtonValue = digitalRead(2);
 if(pushButtonValue == LOW)
 {
  Serial.println("Button pushed");
  digitalWrite(8,HIGH);// turn ON the LED
 }else{
  //Serial.println("Button NOT pushed");
  digitalWrite(8, LOW);// turn OFF the LED
 }
 delay(100);
}

Ресурсы и ссылки

Ресурсов пока нет.

Файлы📁

Нет доступных файлов.