Pages: [1]   Go Down
Author Topic: IR Repeats and Interrupts  (Read 798 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All,

I am new to the Arduino and this is one of my first more advanced sketches. Sorry if this is to much information. Any help is appreciated, I just want to learn!


The Goal of Project:
-To emulate a standing fan using a remote control. The Remote control sends power on signal to IR receiver and turns fan on. Another button from the controller makes the fan rotate\sweep from side to side, couple more buttons change the speed of the rotation\sweep.

This is what i'm currently having problems with. Right when everything is connected up my stepper motor steps 200 rotations clockwise and then goes the other way 200 steps counter-clockwise which rotates\sweeps the DC fan back and forth, works pretty good! Pressing volume up and down changes the speeds of the sweeps. What i'm currently having issues is with sometimes i get 5-6 repeat signals from the IR Remote: FFFFFFFF <-- how do I avoid these repeat signals. Serial Prints for Debugging Purposes.

Hardware)
-Arduino UNO
-12V Stepper Motor\Controller Board
-12V DC Fan
-IR Receiver
-10K Pull Up Resistor to IR Receiver

The Code:

Code:
/*---- Needed Libraries ----*/

//IR Libraries
#include "IRremote.h"
#include "IRremoteInt.h"

//Stepper Motor Libraries
#include <Stepper.h>

//Declare Variables and Constants

//IR
int receiver = 2; // pin 1 of IR receiver to Arduino digital pin 2
volatile int IR_state = HIGH;

//STEPPER
const int stepsPerRevolution = 200; //
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11); //Motor Pin Mapping
volatile int max_speed = 0;


//Declare Objects
IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'

void setup() {
 
  //Start Serial Interface
  Serial.begin(9600);
 
  //Start IR
  Serial.println("IR Receiver Raw Data Decode Test");
  irrecv.enableIRIn(); // Start the receiver
 
  //Set Settper Speed (Default Speed)
  myStepper.setSpeed(4);
 
  //Attach and Enable Interrupt
  attachInterrupt(0, IR_Controll, RISING);
  interrupts();
 
}

void loop()
{

//Run Motor Sweep

//Clockwise
Serial.println("Stepping Start Clockwise");
myStepper.step(stepsPerRevolution);
Serial.println("Stepping Done Clockwise");
delay(200);

//Counter-Clockwise
Serial.println("Stepping Start Counter Clockwise");
myStepper.step(-stepsPerRevolution);
Serial.println("Stepping Done Counter Clockwise");
delay(200);

}


//IR Interrupt
void IR_Controll()
{
  IR_state = !IR_state;
  if (irrecv.decode(&results))
  {
    IR_Translate();
    irrecv.resume();
  }
}

//IR DECODER
void IR_Translate()
{
 
   Serial.println();
   Serial.print("RAW DECODE: ");
   Serial.println(results.value, HEX);
 
   switch(results.value)
   {
     
     //Power
     case 0x10EF08f7:
     Serial.println("Power");
     break;
     
     //Volume Up
      case 0x10EF58A7:
      Serial.println("Volume Up!");
      if (max_speed >= 0 && max_speed <= 2)
      {
      max_speed = max_speed + 1;
      speedcontrol();
      }
      Serial.print("Max Speed ");
      Serial.println(max_speed);
      break;
     
      //Volume Down
      case 0x10EF708F:
      Serial.println("Volume Down");
      if (max_speed >= 1)
      {
      max_speed = max_speed - 1;
      speedcontrol();
      }
      Serial.print("Max Speed ");
      Serial.println(max_speed);
      break;
     
      //Repeat Signal
      case 0xFFFFFFFF:
      Serial.println("Repeat Signal");
      break;
     
      //Unknown Signal
      default:
      Serial.println("Unknown Button Signal");
   
   }
   delay(500);
   }

//STEPPER SPEED CONTROL   
void speedcontrol()
{
//Serial.println("Adjusting Speed");
switch(max_speed)
{
  case 0:
  myStepper.setSpeed(4);
  break;
 
  case 1:
  myStepper.setSpeed(8);
  break;
 
  case 2:
  myStepper.setSpeed(12);
  break;
 
  case 3:
  myStepper.setSpeed(16);
  break;
}

}




« Last Edit: February 02, 2013, 07:56:31 pm by painstream » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What i'm currently having issues is with sometimes i get 5-6 repeat signals from the IR Remote: FFFFFFFF <-- how do I avoid these repeat signals.
Quit holding the button down so long.

Seriously, as long as you don't plan to act on the repeat signal, what difference does it make?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this before posting a programming question

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.


I think remotes are designed to send codes repeatedly, so you can, for example, turn the volume up by holding down the button.

You could:

  • Look for repeated codes and ignore subsequent ones
  • Ignore the same code if it happens within (say) 2 seconds of an earlier one
Logged

Pages: [1]   Go Up
Jump to: