
The rest of the defines list all of the possible I C commands possible. You can toggle each individual relay,
toggle
them all, turn them all on, or turn them all off. There is also a list of commands to check the state of each relay;
whether the relay is
on
or
off
represented numerically by
zero
and
15
respectively.
// Here are the commands to turn on and off individual relays.
#define TOGGLE_RELAY_ONE 0x01
#define TOGGLE_RELAY_TWO 0x02
#define TOGGLE_RELAY_THREE 0x03
#define TOGGLE_RELAY_FOUR 0x04
// Here are the commands to turn them all off or on.
#define TURN_ALL_ON 0xB
#define TURN_ALL_OFF 0xA
//Here is the command to toggle every relay.
#define TOGGLE_ALL 0xC
// Here are the commands to check on the 'status' of the relay i.e. whether the
// relay is on or off.
#define RELAY_ONE_STATUS 0x05
#define RELAY_TWO_STATUS 0x06
#define RELAY_THREE_STATUS 0x07
#define RELAY_FOUR_STATUS 0x08
//Four buttons
const uint8_t yellow_btn = 2;
const uint8_t blue_btn = 3;
const uint8_t red_btn = 4;
const uint8_t green_btn = 5;
Let’s move on. In the following code, we define four buttons that when pressed, will send an I C command to the
associated relay. We have a small delay for debounce of 400 milliseconds associated with each button press. In
the setup is a call to a function that gets the status of the relays:
On
or
Off
represented by
zero
and
15
respectively. This is detailed more extensively just after the next code block.
2
2