JVC Steering wheel remote by arduino

Hi everyone! I have an JVC KW-AV61BT radio, this radio has digital Steering wheel remote line to control radio by keys on wheel. It has the same commands like IR remote conrtol. I need help(
Code:

#define HOLDTIME 500 // Set the time after which the button is considered to be held down
/ * Describe how many "parrots" are in the pressed buttons * /
#define MINUS0 18 // Button "-" on the steering wheel
#define PLUS0 34 // "+" button on the steering wheel
#define CIRCLE0 58 // Button "0" on the steering wheel
#define RIGHT0 91 // ">" button on the steering wheel
#define LEFT0 146 // Button "<" on the steering wheel
#define UP0 241 // Up button on the steering wheel
#define ALLDOWN 447 // All buttons are released
#define DELTA 5 // The error in measuring the incoming signal, if the readings jump by more than 5 units, then you can increase
/ *
Assigning commands to buttons
JVC RM-RK52 remote control commands:
MUTE 0xF171
SOUND 0xF1B1
UP 0xF129
DOWN 0xF1A9
LEFT 0xF1C9
RIGHT 0xF149
SOURCE 0xF111
VOL- 0xF1A1
VOL + 0xF121
* /
// enter commands that will correspond to the pressed button on the steering wheel and the pressed button on the steering wheel
#define UP 0xF111 // Up button on the steering wheel
#define UPH 0xF1B1 // Clamped up button on the steering wheel
#define LEFT 0xF1C9 // Button <
#define LEFTH 0xF1A9 // Held <button
#define RIGHT 0xF149 // Button>
#define RIGHTH 0xF129 // Pressed button>
#define CIRCLE 0xF171 // Button О
#define CIRCLEH 0xF1B1 // Hold down O button
#define PLUS 0xF121 // Button +
#define PLUSH 0xF121 // Pressed + button
#define MINUS 0xF1A1 // Button -
#define MINUSH 0xF1A1 // Pressed button -
boolean flag = false; // Flag that the previously held button works with repetition
int analog = 0; // for reading an analog signal
unsigned long time; // variable for storing time

IRsend irsend;
void setup () {
Serial.begin (9600);
}

void loop () {
analog = analogRead (A0); // read the signal from the ADC pin
// Serial.println (analog); // Uncomment in order to see the current values ​​of the parrots
  
if (abs (ALLDOWN-analog) <DELTA) // in order for the released button to be processed again, reset time to zero
        {
      time = 0;
      flag = false;
}
// Read the value of the button if it is pressed and has not been pressed before (time is zero)
if (abs (ALLDOWN-analog)> DELTA && time == 0)
{
time = millis (); // mark the time of pressing by writing to the time variable
do
{
  Serial.print ("Pushing");
  Serial.print (analogRead (A0));
  Serial.print ("by");
  Serial.println (millis () - time);
  delay (50); // wait, type holdtime
}
while (abs (ALLDOWN-analogRead (A0))> DELTA && millis () - time <= HOLDTIME); // while something is pressed and the time of pressing has not exceeded holdtime
  
if (millis () <time + HOLDTIME && flag == false) // if the hold time is less than holdtime, the helmet signals a single press
// flag is needed so that a released, previously held down button with a repeat is not processed as a single pressed
{
  if (abs (analog-UP0) <DELTA) // 241 button up on the steering wheel
{
irsend.sendJVC (UP, 16.0);
delayMicroseconds (1000);
irsend.sendJVC (UP, 16.0);
Serial.print ("com1");
Serial.println (UP, HEX);
// delay (2000); // For debugging
// 0xF111 Press once this is source
}
if (abs (analog-LEFT0) <DELTA) // 146 button <on the steering wheel
{
irsend.sendJVC (LEFT, 16.0);
delayMicroseconds (1000);
irsend.sendJVC (LEFT, 16.0);
Serial.print ("com1");
Serial.println (LEFT, HEX);
// 0xF1C9 Press it once to the left
}
if (abs (analog-RIGHT0) <DELTA) // 91 button> on the steering wheel
{
irsend.sendJVC (RIGHT, 16,0);
delayMicroseconds (1000);
irsend.sendJVC (RIGHT, 16,0);
Serial.print ("com1");
Serial.println (RIGHT, HEX);
// 0xF149 Press it once to the right
}
if (abs (analog-CIRCLE0) <DELTA) // 58 button 0 on the steering wheel
{
irsend.sendJVC (CIRCLE, 16.0);
delayMicroseconds (1000);
irsend.sendJVC (CIRCLE, 16.0);
Serial.print ("com1");
Serial.println (CIRCLE, HEX);
// 0xF171 Single press is mute
}
if (abs (analog-PLUS0) <DELTA) // 34 + button on the steering wheel
{
irsend.sendJVC (PLUS, 16.0);
delayMicroseconds (1000);
irsend.sendJVC (PLUS, 16.0);
Serial.print ("com1");
Serial.println (PLUS, HEX);
// 0xF121 Single press is vol +
}
if (abs (analog-MINUS0) <DELTA) // 18 button - on the steering wheel
{
irsend.sendJVC (MINUS, 16.0);
delayMicroseconds (1000);
irsend.sendJVC (MINUS, 16.0);
Serial.print ("com1");
Serial.println (MINUS, HEX);
// 0xF1A1 Single press is vol-
 }

}
else if (millis ()> = time + HOLDTIME) // otherwise, when the button was held down, the helmet signals hold
{
if (abs (analog-UP0) <DELTA) // 241 button up on the steering wheel
        {
irsend.sendJVC (UPH, 16.0);
delayMicroseconds (1000);
        irsend.sendJVC (UPH, 16.0);
        Serial.print ("com2");
        Serial.println (UPH, HEX);
 // delay (2000); // for debugging
// 0xF1B1 key pressed is sound
}
if (abs (analog-LEFT0) <DELTA) // 146 button <on the steering wheel
{
        irsend.sendJVC (LEFTH, 16.0);
        delayMicroseconds (1000);
        irsend.sendJVC (LEFTH, 16.0);
        Serial.print ("com2");
        Serial.println (LEFTH, HEX);
// 0xF129 the pressed key is up
}
if (abs (analog-RIGHT0) <DELTA) // 91 button> on the steering wheel
{
        irsend.sendJVC (RIGHTH, 16,0);
        delayMicroseconds (1000);
        irsend.sendJVC (RIGHTH, 16,0);
        Serial.print 

And i have codes from my original IR remote control:

Protocol JVC-48
Address 0x70220103

with SHIFT
Pwr / ATT 0xF2A0
DISP 0xE6B4
Up 0xE8BA
Down 0xE9BB
Left / Prev 0xEFBD
Right / Next 0xEEBC
Rew 0xB7E5
FF 0xB6E4
VOL + 0xF0A2 0xA8FA
VOL- 0xF1A3 0xA9FB
SOURCE 0xF3A1
Play / Pause 0xB1E3
Off-hook / PHONE 0xEDBF
On-hook / Stop 0xFFAD
SETUP / 1 0xA1F3 0x93C1
ASPECT / 2 0xAAF8 0x90C2
RETURN / 3 0xA0F2 0x91C3
TOP M / 4 0xA3F1 0x96C4
Up / 5 0xB8EA 0x97C5
MENU / 6 0xA2F0 0x94C6
Left / 7 0xBFED 0x95C7
ENT / 8 0xBCEE 0x9AC8
Right / 9 0xBEEC 0x9BC9
OSD / * 0xAEFC 0x8EDC
Down / 0 0xB9EB 0x92C0
DUAL / # 0xFDAF 0x8FDD
DIRECT / CLR 0x99CB 0xECBE

I substituted my values, but they did not work, I suspect, because the protocol was not substituted and I do not know how to do it.

What is connected to pin A0?

Read the signal from 0 to 1023.
Detail:

Why take a new reading here?

This means that when the "-" button is pressed (designated as MINUS0), a voltage comes to the input of the arduino A0, which it perceives as 18.
This is how all 6 buttons are described.

Line: #define ALLDOWN 447 // All buttons are released
This constant specifies the amount when all buttons are released.

Line: #define DELTA 5
Due to the fact that the voltage may not be stable, the value may be more or less, so we introduce an error in the measurement - 5.

No, I meant "why take a new reading you do nothing with, and waste another 100us, when you already have a value to print?"

I don't know :slight_smile: I asked about how to send another IR signal and replace it on my value.