当前位置:首页 > 科学研究 > 电子编程 > 正文内容

​Arduino Project 051 - How to Connect Remote Control

RonWang6个月前 (12-17)电子编程321

Project 51 How to Connect Remote Control 4 Channel to Arduino

How to Connect Remote Control 4 Channel to Arduino

// constants won't change. They're used here to set pin numbers:
const   int button1 = 6;    // the number of the pushbutton pin
const int button2 = 7;   
const int ledPin1 = 8;      // the number of the LED pin
const int ledPin2   = 9; 
// Variables will change:
int ledState1 = HIGH;         // the current   state of the output pin
int ledState2 = HIGH;
int buttonState1;             //   the current reading from the input pin
int buttonState2; 
int lastButtonState1   = LOW;   // the previous reading from the input pin
int lastButtonState2 = LOW;
//   the following variables are unsigned long's because the time, measured in miliseconds,
//   will quickly become a bigger number than can be stored in an int.
unsigned long   lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long   debounceDelay = 50;    // the debounce time; increase if the output flickers
void   setup() {
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(ledPin1,   OUTPUT);
  pinMode(ledPin2, OUTPUT);
  // set initial LED state
  digitalWrite(ledPin1,   ledState1);
  digitalWrite(ledPin2, ledState2);
}
void loop() {
   // read the state of the switch into a local variable:
  int reading1 = digitalRead(button1);
   int reading2 = digitalRead(button2);
  
  // check to see if you just pressed   the button
  // (i.e. the input went from LOW to HIGH),  and you've waited
   // long enough since the last press to ignore any noise:
  // If the switch   changed, due to noise or pressing:
  if (reading1 != lastButtonState1) {
     // reset the debouncing timer
    lastDebounceTime = millis();
  }
   if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading   is at, it's been there for longer
    // than the debounce delay, so take it   as the actual current state:
    // if the button state has changed:
     if (reading1 != buttonState1) {
      buttonState1 = reading1;
      //   only toggle the LED if the new button state is HIGH
      if (buttonState1 ==   HIGH) {
        ledState1 = !ledState1;
      }
    }
  }
  //   set the LED:
  digitalWrite(ledPin1, ledState1);
  // save the reading.   Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonState1   = reading1;
  
  
   // If the switch changed, due to noise or pressing:
   if (reading2 != lastButtonState2) {
    // reset the debouncing timer
    lastDebounceTime   = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {
     // whatever the reading is at, it's been there for longer
    // than the   debounce delay, so take it as the actual current state:
    // if the button   state has changed:
    if (reading2 != buttonState2) {
      buttonState2   = reading2;
      // only toggle the LED if the new button state is HIGH
       if (buttonState2 == HIGH) {
        ledState2 = !ledState2;
      }
     }
  }
  // set the LED:
  digitalWrite(ledPin2, ledState2);
   // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
   lastButtonState2 = reading2;
}


版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.donstudio.cn/?id=308

标签: Arduino

相关文章

Arduino Project 002 - LED SOS Morse Code Singal

Arduino Project 002 - LED SOS Morse Code Singal

Arduino 电子编程--灯项目及控制,主要使用Arduino编程控制LED灯,实现基本控制Project 2 LED闪烁S.O.S信号。项目2 Project 2 S.O.S...

Arduino Project 023A - Liquid Crystal Displays - Autoscroll

Arduino Project 023A - Liquid Crystal Displays - Autoscroll

Before wiring the LCD screen to your Arduino board we suggest to solder a pin header strip to the 14...

Arduino Project 011 - Piezo Sounder Alarm

Arduino Project 011 - Piezo Sounder Alarm

Arduino project - sounder and sensors : Include project 11 Piezo Sounder Alarm ,Project piezo sounde...

Books Exploring Arduino

Books Exploring Arduino

Exploring Arduino uses the popular Arduino microcontroller platform as an instrument to teach topics...

Arduino Programming Basic - If and Loop

Arduino Programming Basic - If and Loop

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

Arduino Project 030 - Line Following Robot

Arduino Project 030 - Line Following Robot

Project 30 Line Following RobotUse L298P Driver Line Following Robot Line o...