[code][/code]
floresta wrote:But you are not going to show it to us.... Good luck.
Don
Showing it to you is no problem, except that there are about 8 differnt sections to it, might be a bit long. Ernie
Multitiflash 2 - PTB Version[/color]
By PTB, Ric Batty, Ernie Hatt and Maurice Ribble. http://cameraaxe.com Huge Thanks to http://tronixstuff.com and John Boxall for the outstanding tutorials. Thanks also goes to Omar Francisco and Todd Kurt for the I2C scanning routines http://omarfrancisco.com/i2c-bus-scanner/ http://todbot.com/blog/2009/11/29/i2cscanner-pde-arduino-as-i2c-bus-scanner/ *///=============================================================================================================// REVISIONS:// 0.01 to 0.13 - Initial development.//// 0.14 - Global variables introduced. //// 0.15 - Run_Instant created.// Some tests deactivated.// Trigger pin set to A3.// Changed Trigger from Analog to Digital.// Re-installed edge detect.// Portinput file removed.//// 0.16 - Start introducing main program menu structure.// - Drastically reduced array sizes to try fix memory corruption. Instead of 15 possible modules, currently programming for 2 expansion modules.// - This array reduction fixed current corruption issues.//// 0.17 - Edited Port id code in i2cscan// - Main menu loop working for mode switching. All 3 modes recognised.// - Added allFire routine for waking up flashes.// - Main menu void loop is complete. I think.//// 0.18 - readKeypad renamed to TestKeypad// - created KeypadEntry for use across program// - Edit_constant modified and is now complete// - Run_constant modified//// 0.19 - Edit_Varies modified. Mostly done but is buggy.// - I2Cscan modified// - Memory Corruption returns :(//// 0.20 - Run_Constant and Run_Varies merged to form Run_Sequence. Run_Constant and Run_Varies deleted.// - Run_Sequence complete but only works on module 2. Buggy.//// 0.21 - All test routines deleted.// - General tidying up.// - Edit_Constant changed so that initial delay on first flash is zero instead of same as all consecutive delays.//// 0.22 - Working on Run_Sequence//// 0.23 - Run_Sequence_V2 Alternative triggering routine explored.// - Moving some array setups to I2c scan routine//// 0.24 - MAJOR MILESTONE - ALL MAIN ASPECTS WORKING APART FROM MINOR BUGS// - Adopted new V2 sequencer. Files renamed as necessary// - Fixed bug where Leds and flash ports had incorrect sequencing. Leds 1,2,3,4 = Ports 4,3,2,1. Now Fixed//// 0.25 - Added 2 new modes. Factor_Increasing and Factor_Decreasing//// 0.26 - Reversed Button order to suit buttons being soldered to opposite side of board// - Added Wake flashes button sensing to most parts of program except editing.// - Minor cosmetic changes to Edit_Varies. Still buggy sometimes.//============================================================================================================= //=============================================================================================================// PLANNED FUTURE IMPROVEMENTS://// - Fix the bugs ;)// - Weed out unused variables from declarations.// - Add "Trim" to ports via software to allow microsecond alignment of flashes to be in perfect sync with each other due to different makes or construction quality.// - Enable greater no. of modules. Hangover coding for 2 ports max only may still avail.// - Mapping of surplus ports to actual flashes. Eg. If 3 flash units are plugged in. Some can be fired 2 or 3 times to get 6 or 9 strobes.// - Improve resolution from 1ms to 0.1 ms (ie 100 microseconds)// - Add Backlight control via long press of mode button ?//=============================================================================================================// SOFTWARE MODULES:// Multiflash_2_PTB - Main module. Holds most initiallisations and void setup and void loop. *** WORKING ***// Edit_Constant - Runs the Editing routine to input a single constant value for Run_Constant. *** WORKING ***// Edit_Varies - Runs the Editing routine based on differing values for all found flash ports. *** WORKING *** *** BUGGY ***// Edit_Factor_Increasing - Runs the Editing routine to easily build an array of increasing values. *** WORKING ***// Edit_Factor_Decreasing - Runs the Editing routine to easily build an array of decreasing values. *** WORKING ***// I2CSCAN - Scans the I2C Bus and builds arrays based on hardware found. *** WORKING *** // Run_Sequence - Runs the Triggering routine based on a sequence of delays on all found flash ports. *** WORKING ***// Run_Instant - Runs the Triggering routine based on instantaneous zero delay for all found flash ports. *** WORKING ***// allFire - Subroutine to turn on all flashes on all found flash ports. *** WORKING ***// allOff - Subroutine to turn off all flashes on all found flash ports. *** WORKING ***// KeypadEntry - Keypad Data Entry *** WORKING ***////============================================================================================================= //// Possible I2C Addresses for PCF8574s////#define flashport?? 0x20 // I2C device addresses for PCF8574's A2,A1,A0 => L,L,L//#define flashport?? 0x21 // I2C device addresses for PCF8574's A2,A1,A0 => L,L,H//#define flashport?? 0x22 // I2C device addresses for PCF8574's A2,A1,A0 => L,H,L//#define flashport?? 0x23 // I2C device addresses for PCF8574's A2,A1,A0 => L,H,H//#define flashport?? 0x24 // I2C device addresses for PCF8574's A2,A1,A0 => H,L,L//#define flashport?? 0x25 // I2C device addresses for PCF8574's A2,A1,A0 => H,L,H//#define flashport?? 0x26 // I2C device addresses for PCF8574's A2,A1,A0 => H,H,L//#define flashport?? 0x27 // I2C device addresses for PCF8574's A2,A1,A0 => H,H,H <= Cant use this one. Same as LCD//// Possible I2C Addresses for PCF8574As////#define flashport?? 0x38 // I2C device addresses for PCF8574A's A2,A1,A0 => L,L,L//#define flashport?? 0x39 // I2C device addresses for PCF8574A's A2,A1,A0 => L,L,H//#define flashport?? 0x3A // I2C device addresses for PCF8574A's A2,A1,A0 => L,H,L//#define flashport?? 0x3B // I2C device addresses for PCF8574A's A2,A1,A0 => L,H,H//#define flashport?? 0x3C // I2C device addresses for PCF8574A's A2,A1,A0 => H,L,L//#define flashport?? 0x3D // I2C device addresses for PCF8574A's A2,A1,A0 => H,L,H//#define flashport?? 0x3E // I2C device addresses for PCF8574A's A2,A1,A0 => H,H,L//#define flashport?? 0x3F // I2C device addresses for PCF8574A's A2,A1,A0 => H,H,H//// remember that the IC "sinks" current, that is current runs from +5v through the LED and then to I/O pin// this means that 'high' = off, 'low' = on. //=============================================================================================================//*************************************************************************************************************// Current Problems - Suspect memory corruption introduced in version 0.14. Due to global declarations.// - Variable Delay Entry has display issues when less digit delays are added. Formatting thing.// - Variable Delay Entry is getting random lockups. Often when using previous next buttons.//*************************************************************************************************************//=============================================================================================================//Keypad physically works as confirmed via other sketch with the following keymap and pin numbers.//#include
"Keypad.h"// keypad type definitionconst
byte ROWS = 4;
//four rowsconst
byte COLS = 3;
//three columnschar keys[ROWS][COLS] =
{{
'1',
'2',
'3'},
{
'4',
'5',
'6'},
{
'7',
'8',
'9'},
{
'*',
'0',
'#'}};
byte rowPins[ROWS] = {
2, 3, 4, 5};
//connect to the row pinouts of the keypadbyte colPins[COLS] = {
6, 7, 8};
// connect to the column pinouts of the keypadint count=0;
Keypad keypad =
Keypad(
makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//=============================================================================================================#include
"Wire.h"#include <i2cscanner.h>
using Utilities::I2CScanBus;
//=============================================================================================================#include <
LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
// set the LCD address to 0x27 for a 20 chars and 4 line display//=============================================================================================================// Set up the analog input pin for the trigger signal const
int TriggerPin = A3;
// the number of the pushbutton pin Analog 3 int TriggerState =
HIGH;
// variable for reading the trigger status//=============================================================================================================// Set up general variables int ModeCurrent=0;
// 0=Instant,1=Constant,2=Varies//=============================================================================================================//Setup LED const
int ledPin1 = A1;
// the number of the pushbutton pin Digital A1//=============================================================================================================// Setup Buttons// set pin numbers:// const int buttonPin1 = 9; // the number of the pushbutton pin Digital 9// const int buttonPin2 = 10; // the number of the pushbutton pin Digital 10// const int buttonPin3 = 11; // the number of the pushbutton pin Digital 11// const int buttonPin4 = 12; // the number of the pushbutton pin Digital 12// const int buttonPin5 = 13; // the number of the pushbutton pin Digital 13// const int buttonPin6 = A2; // the number of the pushbutton pin Analog 2 const
int buttonPin1 = A2;
// the number of the pushbutton pin Digital 9 const
int buttonPin2 = 13;
// the number of the pushbutton pin Digital 10 const
int buttonPin3 = 12;
// the number of the pushbutton pin Digital 11 const
int buttonPin4 = 11;
// the number of the pushbutton pin Digital 12 const
int buttonPin5 = 10;
// the number of the pushbutton pin Digital 13 const
int buttonPin6 = 9;
// the number of the pushbutton pin Analog 2 int buttonState1 =
HIGH;
// variable for reading the pushbutton status MODE int buttonState2 =
HIGH;
// variable for reading the pushbutton status EDIT int buttonState3 =
HIGH;
// variable for reading the pushbutton status PREVIOUS int buttonState4 =
HIGH;
// variable for reading the pushbutton status NEXT int buttonState5 =
HIGH;
// variable for reading the pushbutton status WAKE int buttonState6 =
HIGH;
// variable for reading the pushbutton status ACTIVATE int ButtonPressed = 0;
//=============================================================================================================// Set up I2C Scanning and Module Array Variables. Currently set for 2 modules max due to memory corruption. int CodesInputStandard [4] = {247, 251, 253, 254};
// Codes for Input Show// int CodesTriggerStandard [4] = {119, 51, 17, 0}; // Codes for Flash Trigger Sequence *** error*** LEDS 1234 => Flashes 4,3,2,1 int CodesTriggerStandard [4] = {231, 195, 129, 0};
// Codes for Flash Trigger Sequence int PortsStandard[4];
// 4 Ports per Module int FlashesRun[8];
// 60 possible flashes (15 x 4) Flash indices int PortsRun[8];
// 60 possible flashes (15 x 4) Flash Port ID int ModulesIdEdit[8];
// 60 possible flashes (15 x 4) Flash Port ID <= Module Index 1, 2, 3 etc.... int CodesTriggerRun [8];
// 60 possible flashes (15 x 4) Flash Port ID int DelaysRun [8];
// 60 possible flashes (15 x 4) Flash Port ID <= actual delay values int ModulesDecDetect [2];
// 15 possible modules int PossibleModuleAddresses[] = {32, 33, 34, 35, 36, 37, 38, 56, 57, 58, 59, 60, 61, 62, 63};
// remember we cant use 39 int ModuleQuantity;
int FlashQuantity;
int DelayConstant;
//=============================================================================================================// Set up Triggering Variables int triggerInput;
unsigned long triggerTime;
// Time of input trigger unsigned long rTime;
// Relative time, time relative to the trigger start byte edgeDetect;
// Used to require the triggering signal to go high again before re-triggering the action. (Might be superseeded by RIC check) .Re-added by PTB. False triggers were happening. int currentTime;
//=============================================================================================================void setup()
{
//=============================================================================================================// Setup LEDS// set pin numbers: const
int ledPin1 = A1;
// the number of the pushbutton pin Digital A1// initialize the LED pins as outputs: pinMode (ledPin1,
OUTPUT);
// sets the digital pin as output//=============================================================================================================// Setup I2C Bus Wire.
begin();
Serial.
begin(19200);
//=============================================================================================================// Setup Buttons// Initialize the pushbutton pins as inputs: pinMode(buttonPin1,
INPUT);
pinMode(buttonPin2,
INPUT);
pinMode(buttonPin3,
INPUT);
pinMode(buttonPin4,
INPUT);
pinMode(buttonPin5,
INPUT);
pinMode(buttonPin6,
INPUT);
// Turn on Pull up resistors digitalWrite(buttonPin1,
HIGH);
// turns on pull-up resistor after input digitalWrite(buttonPin2,
HIGH);
// turns on pull-up resistor after input digitalWrite(buttonPin3,
HIGH);
// turns on pull-up resistor after input digitalWrite(buttonPin4,
HIGH);
// turns on pull-up resistor after input digitalWrite(buttonPin5,
HIGH);
// turns on pull-up resistor after input digitalWrite(buttonPin6,
HIGH);
// turns on pull-up resistor after input//=============================================================================================================// Setup Trigger input pin pinMode(TriggerPin,
INPUT);
digitalWrite(TriggerPin,
HIGH);
// turns on pull-up resistor after input//=============================================================================================================//Splash Screen / Welcome Message lcd.
init();
// initialize the lcd lcd.
backlight();
lcd.
setCursor(0, 0);
delay(100);
lcd.
setCursor(3, 0);
lcd.
print(
"Multiflash 2");
lcd.
setCursor(2, 1);
lcd.
print(
"PTB Version 0.26");
lcd.
setCursor(5, 2);
lcd.
print(
"CameraAxe");
lcd.
setCursor(4, 3);
lcd.
print(
"Enhancement");
delay(2000);
//============================================================================================================= I2CScan();
//=============================================================================================================// The PCF8574N defaults to high, so this function turns all outputs off allOff();
}
//end Void Setup//=============================================================================================================//=============================================================================================================//=============================================================================================================void loop()
{
ButtonPressed=0;
lcd.
clear();
lcd.
setCursor(0, 0);
switch(ModeCurrent) {
case 0:
lcd.
setCursor(3, 1);
lcd.
print(
"Instant Trigger");
lcd.
setCursor(8, 2);
lcd.
print(
"Mode");
break;
case 1:
lcd.
setCursor(3, 1);
lcd.
print(
"Constant Delay");
lcd.
setCursor(8, 2);
lcd.
print(
"Mode");
break;
case 2:
lcd.
setCursor(3, 1);
lcd.
print(
"Variable Delay");
lcd.
setCursor(8, 2);
lcd.
print(
"Mode");
break;
case 3:
lcd.
setCursor(1, 1);
lcd.
print(
"Increasing Factor");
lcd.
setCursor(8, 2);
lcd.
print(
"Mode");
break;
case 4:
lcd.
setCursor(1, 1);
lcd.
print(
"Decreasing Factor");
lcd.
setCursor(8, 2);
lcd.
print(
"Mode");
break;
default:
lcd.
clear();
}
//end switch delay(100);
//Slow screen refresh//=============================================================================================================// Read Buttons buttonState1 =
digitalRead(buttonPin1);
//Button1 = Mode if (buttonState1 ==
LOW)
{
delay(100);
ButtonPressed = 1;
ModeCurrent = ModeCurrent + 1;
// 0=Instant,1=Constant,2=Varies,3=Factor Increasing,4=Factor Decreasing if ( ModeCurrent == 5) ModeCurrent = 0;
}
//end if buttonstate1 buttonState2 =
digitalRead(buttonPin2);
//Button2 = Edit if (buttonState2 ==
LOW)
{
delay(100);
ButtonPressed = 2;
switch(ModeCurrent) {
case 0:
break;
case 1:
Edit_Constant();
break;
case 2:
Edit_Varies();
break;
case 3:
Edit_Factor_Increasing();
break;
case 4:
Edit_Factor_Decreasing();
break;
default:
break;
}
//end switch }
//end if buttonstate2 // Note: Buttons 3 and 4 Previous and Next are inactive in this context. buttonState5 =
digitalRead(buttonPin5);
//Button5 = Wake all flashes. ie send a pulse if (buttonState5 ==
LOW)
{
delay(100);
ButtonPressed = 5;
allFire();
delay(500);
allOff();
}
//end if buttonstate5 buttonState6 =
digitalRead(buttonPin6);
//Button6 = Activate if (buttonState6 ==
LOW)
{
delay(100);
ButtonPressed = 6;
switch(ModeCurrent) {
case 0:
Run_Instant();
break;
case 1:
Run_Sequence();
//Now same for cases 1 to 4 break;
case 2:
Run_Sequence();
//Now same for cases 1 to 4 break;
case 3:
Run_Sequence();
//Now same for cases 1 to 4 break;
case 4:
Run_Sequence();
//Now same for cases 1 to 4 break;
default:
break;
}
//end switch }
//end if buttonstate6 //=============================================================================================================}
//end void loop[/quote]