I'm programming a learn mode to store RC Switch signal, and I'm having some issues with the bitWrite function.
Code: --- |
---|
``` if (LearnMode == 1){ |
remotecontrol1 = remotecontrolsignal; |
bit1R1 = bitRead(remotecontrol1, 4); |
bit2R1 = bitRead(remotecontrol1, 5); |
if (bit1R1 == 1 && bit2R1 == 0){ //Received signal using button 1, so store code from button 1, change bits and store button 2 and button 3. |
remotecontrol1B1 = remotecontrol1; |
Serial.println("Button 1"); |
EEPROM.put(EEPROMaddrR1B1, remotecontrol1B1); //bits 4 and 5 are 10, it means button 1. |
bitWrite(remotecontrol1B1, 4, 0);
bitWrite(remotecontrol1B1, 5, 1);
remotecontrol1B2 = remotecontrol1B1;
EEPROM.put(EEPROMaddrR1B2, remotecontrol1B2); //bits 4 and 5 now are 01, it means button 2.
bitWrite(remotecontrol1B1, 4, 1);
bitWrite(remotecontrol1B1, 5, 1);
remotecontrol1B3 = remotecontrol1B1;
EEPROM.put(EEPROMaddrR1B3, remotecontrol1B3); //bits 4 and 5 now are 11, it means button 3.
Serial.println("LearnMode DISABLED");
LearnMode = 0;
}
```
|
and it gives me this values:
remotecontrolsignal: 1011011010100010101011010101 (this is the input from the remote).
remotecontrol1B1: 101010111101011110010111010101
remotecontrol1B2: 1101010001010101111010111100101
remotecontrol1B3: 1011011010100010101011110101
But if I use a code where I input this binary and change it using bitWrite, everything works perfectly. So I don't see why it adds more bits instead of changing it in this code.
I'm saving separated values for each button because I tried to save just the "id" (first 22 bits) and use bitRead to see which button was pressed but I couldn't find a way to do that (save just the ID).
I'm new to programming and the forum, so any suggestions or advice are welcomed.