Hi mstanley,
Thank you so much for getting back to me so quickly!
The code is so nice and elegant! And I love the dimming loop, it’s genious! 
I just realised that I’ve omitted some important information… I probably should have mentioned this before; this code will be for one Arduino which will make a post to the Raspberry Pi 2 MQTT broker, while another Arduino will listen to the post messages from all of the posting arduinos. This is currently working, and because all the posting Arduino will do is just that – post, it will not be able to ascertain what state each of the 50 LED downlights is in (well, not without making the code much larger), therefore I may need to internally store the toggled state of each light within the posting unit.
For all intents and purposes, this operation works, the only thing which will vary is the posted message, which is based upon the switch and state of the light, if that makes sense…
I apologise for the layout of this message, I've formulated it in a word doc, which didn't preserve the nice layout and indentation I had.
Just to confirm that I’ve got the operation and flow of this code correct…
Is it correct to assume that the ‘delayTime’ is assigned at the time of declaration – I don’t see a value assigned anywhere else?
Say, for example the user presses 1:
Iteration 1:
Keypad.getKey() returns ‘1’,
The ‘keypadEvent(KeypadEvent key)’ event handler sees the event and starts to execute,
The first thing that is registered is the ‘PRESSED’ state,
Then because the key is NOT a ‘#’, exit the switch statement and return to the loop() function,
Next, the key evaluation will print the ‘lightState’ condition of ‘ON’,
Finally, the adjust and lightState conditions are both evaluated to false and the code block is not entered - End of iteration 1.
Iteration 2:
Keypad.getKey() is still ‘1’,
The keypadEvent(KeypadEvent key) handler is again invoked,
The next state registered is the ‘RELEASED’ state,
Again, because the key is not a ‘#’, exit the switch statement and return to the loop() function,
Again, the key evaluation will print the ‘lightState’ condition of ‘ON’ – End of iteration 2.
Judging by this, the light will never be turned on? And only toggled if the ‘#’ is pressed?
This is the bit I’m confused with.
Please let me know if I’ve gone waaaay of the mark here…
If I make the event handler evaluate each switch state against the locally stored switch variable and adjust accordingly as per below, do you think this could work?
void keypadEvent(KeypadEvent key)
{
/* Convert 'key' char array in declaration to a byte array to do math evaluation or cast it as required*/
/* Determine if the switch state is odd(on) or even(off) - if even decrease key value
global variable (or pass it as local) to be posted and vice versa*/
byte oddEven = (key % 2) ? key-- : key++;
switch (keypad.getState())
{
case PRESSED:
if (millis() - startTime > delayTime) //Assign delay value upon declaration?
{
toggleLight = true;
}
break;
case HOLD:
adjust = true;
toggleLight = false;
break;
case RELEASED:
if (toggleLight == true)
{
client.publish("switchStateId", key); // Do this post
digitalWrite(lightPin,!lightState); // Instead of this.
lightState = digitalRead(lightPin);
}
startTime = millis(); // Reset our toggle delay timer. // what happens after 50 days?
adjust = false;
break;
}
}
Lastly, I've briefly read about the millis() function, it seems like a really clever way to determine the time passed, but what happens after it resets itself in roughly 50 days time? What will happen to the dependent variables if the time passed is now less than what it previously was?
Again, thank you so much for your time, I really appreciate it!!