CODE | How to Connect Remote Control - Arduino Project 047

RonWang1 years ago (2024-11-07)电子编程 COD50

In the first time I purchase this remote, I don't know why the operating mode is only non-latched, I was wondering why?. Maybe because of the cheap price, so the producer doesn't add a relay to it. So, then I try to find a way so this remote can be used for controlling power plug with latched operating mode (instead of non-latched mode).

Project 047 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;
}
Share with Friends:

Related Articles

Identifying Color-Band Resistors and Reading Their Values

Identifying Color-Band Resistors and Reading Their Values

色环电阻的识别与数值读取色环电阻是在电阻封装上(即电阻表面)涂上一定颜色的色环,来代表这个电阻的阻值。色环实际上是早期为了帮助人们分辨不同阻值而设定的标准。色环电阻应用还是很广泛的,如家用电器、电子仪…

CODE | Joystick Servo Control - Arduino Project 027

CODE | Joystick Servo Control - Arduino Project 027

In this tutorial, we are going to learn how to use Arduino and a joystick to control two servo motor…

CODE | Servo Control - Arduino Project 025

CODE | Servo Control - Arduino Project 025

You will need to obtain a standard RC servo; any of the small or mid-sized servos will do. Larger se…

CODE | Liquid Crystal Displays Autoscroll - Arduino Project 023A

CODE | Liquid Crystal Displays Autoscroll - Arduino Project 023A

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

CODE | Light Sensor - Arduino Project 014

CODE | Light Sensor - Arduino Project 014

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp…

CODE | Simple Ultrasonic Range HC-SR04 - Arduino Project 038

CODE | Simple Ultrasonic Range HC-SR04 - Arduino Project 038

Ultrasonic range finders measure distance by emitting a pulse of ultrasonic sound that travels throu…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.