Having got the LED pattern working (and huge thanks to Marco), I wanted to add a little more hardware to the Arduino.
I wanted to add a little more code that listens to one of the pins for various PWM signals and if they are within a certain range, action by calling a subroutine.
However it seems to lock out some of the LED patterns. I essentially want to the LED pattern to continue if that is possible ?
Can anyone suggest where I have gone wrong please ?
#include "Multi_Blink2.h" // type definitions
#include <multiCameraIrControl.h>
Sony Nex5(9);
int z=100;
// Blink Table T - Modify this table to suit whatever the output requirements are
// Add or delete lines as required to achieve the desired effects.
// To add additional states the structure in the header file needs to be modified
//
ledTable T[] =
//Pin St Lopp State 0 State 1 State 2 State 3 State 4 Wkup
{
{ 11, 0, 0, {{MB_LOW, 1500, 0}, {MB_HIGH, 35, 0}}, 0 }, //
{ 0, 0, 0, {{MB_HIGH, 20, 0}, {MB_LOW, 50, 0}, {MB_LOOP, 3, 0}, {MB_HIGH, 250, 0}, {MB_LOW, 450, 0}}, 0 }, //
{ 1, 0, 0, {{MB_HIGH, 20, 0}, {MB_LOW, 50, 0}, {MB_LOOP, 3, 0}, {MB_HIGH, 250, 0}, {MB_LOW, 450, 0}}, 0 }, //
{ 5, 0, 0, {{MB_LOW, 450, 0}, {MB_HIGH, 20, 0}, {MB_LOW, 50, 0}, {MB_LOOP, 3, 1}, {MB_HIGH, 250, 0}}, 0 }, //
{ 7, 0, 0, {{MB_LOW, 450, 0}, {MB_HIGH, 20, 0}, {MB_LOW, 50, 0}, {MB_LOOP, 3, 1}, {MB_HIGH, 250, 0}}, 0 }, //
{ 2, 0, 0, {{MB_HIGH, 35, 0}, {MB_LOW, 1500, 0}}, 0 },
};
// Self adjusting constants for loop indexes
#define MAX_STATE (sizeof(T[0].state)/sizeof(stateDef))
#define MAX_LED (sizeof(T)/sizeof(ledTable))
#define FADE_IN 0
#define FULL_BRIGHT 1
#define FADE_OUT 2
#define FADE_DELAY 45 //ms
#define FULL_DELAY 70 //ms
#define FRONT_LED 11
#define FADE_MAX 30 // max PWM value
#define FADE_MIN 1
void setup()
{
Serial.begin(9600); // Debug via serial window
delay (2500);
pinMode(FRONT_LED, OUTPUT);
pinMode (11, OUTPUT); // On board status LED
pinMode(A0, INPUT); // RC PMM Signal input
// pinMode(LED_PIN2, OUTPUT);
for (int i=0; i < MAX_LED; i++)
{
pinMode(T[i].ledPin, OUTPUT);
T[i].nextWakeup = 0;
digitalWrite(T[i].ledPin, LOW);
T[i].currentLoop = LOOP_UNDEF;
}
}
void loop()
{
z = pulseIn(A0, HIGH, 20000);
if (z>1155 && z<1170) {
Nex5.shutterNow();
}
if (z>1780 && z<1820) {
Nex5.shutterNow();
delay(1500);
}
if (z>1430 && z<1500) {
Nex5.videoToggle();
delay(500);
}
for (int i=0; i < MAX_LED; i++)
{
// check if the state active time has expired (ie, it is less than current time)
if (millis() >= T[i].nextWakeup)
{
T[i].nextWakeup = millis() + T[i].state[T[i].currentState].activeTime;
switch (T[i].state[T[i].currentState].activeVal)
{
case MB_LOW:
case MB_HIGH: // Write digital value
digitalWrite(T[i].ledPin, T[i].state[T[i].currentState].activeVal == MB_HIGH ? HIGH : LOW);
T[i].currentState = (++T[i].currentState) % MAX_STATE;
break;
case MB_LOOP: // loop back to specified state if there is still count left
// first time in this state set the loop counter
if (T[i].currentLoop == LOOP_UNDEF)
{
T[i].currentLoop = T[i].state[T[i].currentState].activeTime;
}
// loop around or keep going?
if (T[i].currentLoop-- > 0)
{
T[i].currentState = T[i].state[T[i].currentState].nextState;
T[i].nextWakeup = 0; // do it immediately
}
else
{
T[i].currentLoop = LOOP_UNDEF; // set up loop counter
T[i].currentState = (++T[i].currentState) % MAX_STATE;
}
break;
default: // just move on - handles NULL and any stupid states we may get into
T[i].currentState = (++T[i].currentState) % MAX_STATE;
break;
}
}
}
}