Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino nano + HC-06 bluetooth
#18
Probaj ovako :

Code:
#include <IRremote.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

#include <IRremote.h>

IRrecv irrecv(RECV_PIN);
decode_results results;
const int RECV_PIN = 12;
const int volumeup = 10;
const int volumedown = 9;
const int mute = 8;

unsigned long key_value = 0;


void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(volumeup, OUTPUT);
  pinMode(volumedown, OUTPUT);
  pinMode(mute, OUTPUT);
}

void loop(){
    if (irrecv.decode(&results)){
       
        if (results.value == 0XFFFFFFFF)
          results.value = key_value;

        switch(results.value){
          case 0xF7CB: //Keypad button "5"
          digitalWrite(volumeup, HIGH);
          delay(100);
          digitalWrite(volumeup, LOW);
          }

        switch(results.value){
          case 0xF74B: //Keypad button "2"
          digitalWrite(volumedown, HIGH);
          delay(100);
          digitalWrite(volumedown, LOW);
          }
     
          switch(results.value){
          case 0xF702: //Keypad button "2"
          digitalWrite(mute, !digitalRead(mute));
          delay(1000);
          //digitalWrite(mute, LOW);
          }

        key_value = results.value;

        irrecv.resume();
    }
}

Tamo na sajtu pise :

Quote:Before the switch block starts there is a conditional block:

if (results.value == 0XFFFFFFFF)
results.value = key_value;
If we receive 0XFFFFFFFF from the remote, it means a repetition of the previous key. So in order to handle the repeat key pattern, I am storing the hex code in a global variable key_value every time a code is received:

key_value = results.value;

When you receive a repeat pattern, then the previously stored value is used as the current key press.

At the end of the void loop() section, we call irrecv.resume() to reset the receiver and prepare it to receive the next code.
Reply


Messages In This Thread
Arduino nano + HC-06 bluetooth - by Khadgar2007 - 07-05-2019, 02:10 PM
RE: Arduino nano + HC-06 bluetooth - by gorankg - 07-05-2019, 04:34 PM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 07-05-2019, 06:20 PM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 07-05-2019, 08:34 PM
RE: Arduino nano + HC-06 bluetooth - by gorankg - 07-05-2019, 07:10 PM
RE: Arduino nano + HC-06 bluetooth - by gorankg - 07-05-2019, 08:13 PM
RE: Arduino nano + HC-06 bluetooth - by gorankg - 07-06-2019, 07:10 AM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 10-31-2020, 12:25 AM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 10-31-2020, 12:42 AM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 10-31-2020, 06:04 PM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 10-31-2020, 11:33 PM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 11-01-2020, 10:41 AM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 11-01-2020, 01:58 PM
RE: Arduino nano + HC-06 bluetooth - by me[R]a - 11-01-2020, 02:33 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)