Untested, only compiled.
Generates identical warnings.
#include <IRremote.h>
const uint8_t analogPin = A0;
const uint16_t threshold = 405;
const uint32_t idleTime = 15000;
const uint32_t burstPacketSpacing = 40;
const uint8_t numberOfBurstPackets = 4;
const uint32_t burstSpacing = 1000;
enum sStates {
wait15seconds,
checkInput,
sendFirstBurst,
waitBetweenBursts,
sendSecondBurst,
} pgmState = wait15seconds;
IRsend irsend;
void setup() {}
void loop() {
static uint32_t lastStateSwitch;
static uint8_t burstPacketCount;
uint32_t topLoop = millis();
switch (pgmState) {
case wait15seconds:
if (topLoop - lastStateSwitch >= idleTime) {
pgmState = checkInput;
lastStateSwitch = topLoop;
}
break;
case checkInput:
if (analogRead(analogPin) > threshold) {
pgmState = sendFirstBurst;
burstPacketCount = 0;
lastStateSwitch = topLoop;
}
break;
case sendFirstBurst:
if (topLoop - lastStateSwitch >= burstPacketSpacing) {
irsend.sendSony(0x2B09, 15);// 2B09 15
lastStateSwitch = topLoop;
if (++burstPacketCount >= numberOfBurstPackets) {
pgmState = waitBetweenBursts;
}
}
break;
case waitBetweenBursts:
if (topLoop - lastStateSwitch >= burstSpacing) {
pgmState = sendSecondBurst;
burstPacketCount = 0;
lastStateSwitch = topLoop;
}
break;
case sendSecondBurst:
if (topLoop - lastStateSwitch >= burstPacketSpacing) {
irsend.sendSony(0x4B09, 15);// 4B09 15
lastStateSwitch = topLoop;
if (++burstPacketCount >= numberOfBurstPackets) {
pgmState = wait15seconds;
}
}
break;
}
}
I could have shortend the code by using fallthrough on some (or most?) cases,
but that - and the optical clutter to get rid of the warnings -
would somehow hurt the example character of the sketch.