Hi, Im new to arduino and on my first project. Im trying to get codes from a 433mhz remote so I can control remote power sockets from a 4 by 4 keypad. The control has on and off buttons for each adapter instead of just 1 button for on and off. Iv got it working using 2 buttons for on and off but I wanted to use just one button to turn each socket on and off. Has anyone got any ideas how I could do this please. Here is some sample code I am using:
#include <Keypad.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
const byte ROWS = 4;
const byte COLS = 4;
// Define the Keymap
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 5, 4, 3, 2 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
mySwitch.setPulseLength(190);
Serial.begin(9600);
}
void loop()
{
char key = kpd.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
case '1':
mySwitch.send("000101010101110100000011"); \button on code
break;
case '2':
mySwitch.send("000101010101110100001100"); \button off code
break;
default:
Serial.println(key);
}
}
}
Thanks