Hello everyone, this is my 1st post on this forum. I am working on a small project, which require remote control of DC motor. I've used IRremote library from arduino, basic IR remote (cheapest possible with 9 numbres and UP, LEFT, DOWN, RIGHT, OK buttons) and VS1883B sensor.
Right now, i can control my motor with basic instructions: click -> forward -> click -> stop -> click -> backward -> click -> stop etc.
I want to control my motor by holding a button (motor should move when button is hold and stop when i release a button). I've read tons of similar threads, but most of them require remote which sends "repeat code" (0xFFFFFF etc), but my remote / sensor doesnt register any "reapeat code". My cheap IR remote doesnt not "spam" codes when i hold a button, it just send one, single code.
I've also tried my TV remote. This one is "spamming" codes when i hold a button.
Whats the difference between my cheap remote and TV remote? Why cheap one sends just one code and TV remote is spamming codes again and again?
Is it possible to implement something which would help my cheap remote to control motor while holding a button? Should i use interrupts and timers?
This is my current source code with basic control:
#include <IRremote.h>
int input_pin = 2;
IRrecv irrecv(input_pin);
decode_results signals;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(6, OUTPUT); //PWM
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop() {
if (irrecv.decode(&signals)) {
Serial.println(signals.decode_type);
Serial.print(F("received code = 0x"));
Serial.println(signals.value, HEX); //hex value
irrecv.blink13(true); //blink leds when code is received
if (signals.value == 0x3D9AE3F7 )//go up
{
analogWrite(6, 255);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
delay(50);
}
if (signals.value == 0x1BC0157B)
{ //go down
analogWrite(6, 255);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
delay(50);
}
if (signals.value == 0x488F3CBB) { //stop
analogWrite(6, 0);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(100);
}
irrecv.resume();
delay(100);
}
}