How can I reset the results.value to 0

How can I reset the results.value to 0 every press. e.g. when I press 2 my motor will go continuously but if I can sent the 0 value it will move while I'm pressing and stop when unpressed it

#include <pop7.h> // IPST-SE Board
#include <IRremote.h> // Include IR remote control library
IRrecv irrecv(24);
decode_results results;
void setup(){   
setTextSize(2); // Set text size of GLCD-XT
glcdClear(); // Clear screen of GLCD-XT
irrecv.enableIRIn(); // Enable the IR module operation1
Serial.begin(9600);

}
void loop(){
if (irrecv.decode(&results  )){
if (results.decode_type == SONY){
if (in(8)&& !in(9)) {  
sr(50);}
if(results.value == 16){ glcd(0,0,"Button 1");} //Num1
else if(results.value == 2064){fd(100); delay(100); fd(0); } //Num2
else if(results.value == 1040){glcd(0,0,"Button 3"); }//Num3
else if(results.value == 3088){sl(50); }//Num4}
else if(results.value == 528){servo(1,90); }//Num5
else if(results.value == 2576){sr(50); }//Num6
else if(results.value == 1552){glcd(0,0,"Button 4"); }//Num7}
else if(results.value == 3600){bk(50); }//Num8
else if(results.value == 272){glcd(0,0,"Button 3"); }//Num9
else if(results.value == 2320){glcd(0,0,"Button 4"); }//Num0}
else if(results.value == 336){servo(1,0); } //soundmode
else if(results.value == 2384){glcd(0,0,"Button 3"); } //surround
else if(results.value == 1168){glcd(0,0,"Button 4");} //vol up}
else if(results.value == 144){glcd(0,0,"Button 3"); } //prog+
else if(results.value == 3216){glcd(0,0,"Button 4"); }//vol down}
else if(results.value == 656){glcd(0,0,"Button 3"); } //mute
else if(results.value == 2704){glcd(0,0,"Button 4");} //turn off/on}
else if(results.value == 112){glcd(0,0,"Button 3"); }//menu
else if(results.value == 2192){glcd(0,0,"Button 4");} //prog-

}
irrecv.resume();
Serial.println(results.value);

}
}

can you explain what you mean ? what's the code of your '0' key ?

Calling decode with a parameter is obsolete and is not supported in the new version of the library. Are you sure you are using the correct version?

That is not something you can do easily with an IR remote.
If the remote sends a code repeatedly while the button is pressed or sends a special 'repeat' code while the button is still pressed, you can use a timer to stop your motor if the code or 'repeat' code has not arrived as often as expected.

Does your remote keep sending while the button is down?

It can be other number. Main thing that I want to do is to stop motor when not press it. This is one of my ideas that if I'm not pressed, results.value will be 0.

Please share the link to the IRRemote library what you used. The standard Arduino IRRemote doesn't support the method:

Remote controllers work in different ways when you hold down a button. Some will only send the button code once - so you can’t know when the key is released nor how long it was held down, some rare ones will send the same key every x ms as long as you hold the button down and most will send a generic repeat key code to mention that the key is still held down but it’s not a new press.

It is very likely your remote behaves like the latter one so you should trap that repeat code and program a timeout that says

If I receive a code 
  If it’s the repeat code 
    Then update the timeout moment 
  Else
    Stop the current action and do the new one

Else If I did not receive a code (repeat or different) in the last x ms
  Then stop 

IRremote - Arduino Libraries version3.9.0

You need that only because your logic of reading of results.value is incorrect.
Look in the code - you read the IR code value at the start of the each loop() run, even if no new data was arrived. So if there is no button pressed, you get outdated results.value.

I think you should change the logic - Instead of unconditional reading of results, first test either a new data received with

irrecv.available() 

method and get the new value if new data arrived only.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.