4x4 keypad to set a delay length for intervalometer

Hi

I’m pretty new to Arduino, though have been running trough the various projects for a week and have learnt so much. Time to now actually put some of it to good use!

I am building a intervalometer for a Sony camera. I have found source code to trigger the shutter and can amend the delay length via the TimeBetweenShots variable. However, I want to use a 4x4 keypad to select from different delay lengths programmed to each key. For example, if I want a 3 second shutter delay, I press ‘1’ on the keypad.

I managed to include a potentiometer into the code to adjust the length, though was only able to get up to a second delay, so switched to a keypad.

How can I use the keypad to change the TimeBetweenShots variable?

Here is the code so far:

// Some Declarations
unsigned long TimeBetweenShots = 1000;    // Time in mS 60000 = 60 Seconds
int IRled = 12;                // IR Output Signal to Anode of IR LED 
// Cathode of IR LED to ground through a 150 Ohm Resistor.
int Begin = 13;               // Indicates Shutter Start on LED
int potPin = A2;    // select the input pin for the potentiometer

// Code to send Shutter release command B4B8F
int SCodeBits[] = {1,0,1,1,0,1,0,0,1,0,1,1,1,0,0,0,1,1,1,1};


#include <Keypad.h>

const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]= 
{
{'1', '2', '3', 'A'}, 
{'4', '5', '6', 'B'}, 
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);


void setup()
{
  // Setup IRLed and Begin Led Pins as outputs
  pinMode(IRled, OUTPUT);      // sets the digital pin as output
  pinMode(Begin, OUTPUT);      // sets the digital pin as output
}


  

// Infinite Loop 
void loop(){


  digitalWrite(Begin, HIGH);  // Signal Begin LED ON

  for (int i=1; i <= 3; i++)  // Send Command 3 times as per Sony Specs
  {
    header();                    // Send the Start header
    for (int i=0; i <= 19; i++)  // Loop to send the bits
    {
          if(SCodeBits[i] == 1)  // Is Data_is_One to be sent ?
          {
            Data_is_One();              // Yes, send a Data_is_One bit
          }
          else                  // No, Data_is_Zero to be sent
          {
            Data_is_Zero();              // Send a Data_is_Zero bit
          }
    }
    delay(11);                  // Delay Padding to give approx 45mS between command starts
  }
  digitalWrite(Begin, LOW);     // Begin LED OFF
  delay(TimeBetweenShots);      // Hang about wasting time before next shot
}

// Routine to give the 40kHz burst signal
void burst()                   // 40KHz burst
{
  digitalWrite(IRled, HIGH);   // sets the pin on
  delayMicroseconds(10);       // pauses for 13 microseconds  (fudged to 10uS Delay)   
  digitalWrite(IRled, LOW);    // sets the pin off
  delayMicroseconds(8);        // pauses for 12 microseconds   (fudged to 8uS Delay)
}

// Routine to give a quiet period of data
void quiet()                   // Quiet burst
{
  digitalWrite(IRled, LOW);    // sets the pin off
  delayMicroseconds(10);       // pauses for 13 microseconds   (fudged to 10uS Delay)  
  digitalWrite(IRled, LOW);    // sets the pin off
  delayMicroseconds(8);        // pauses for 12 microseconds    (fudged to 8uS Delay)
}

// Routine to send header data burst
// This allows the IR receiver to set its AGC (Gain)
// Header Burst Timing is 96 * 0.025uS = 2.4mS
// Quiet Timing is 24 * 0.025uS = 600uS
void header() 
{
    for (int i=1; i <= 96; i++){
      burst();                // 40kHz burst
    }
    for (int i=1; i <= 24; i++){
      quiet();                // No 40 kHz
    }
}

// Routine to send one data burst
// Burst Timing is 48 * 0.025uS = 1.2mS
// Quiet Timing is 24 * 0.025uS = 600uS
void Data_is_One()
{
    for (int i=1; i <= 48; i++){
      burst();                // 40kHz burst
    }
    for (int i=1; i <= 24; i++){
      quiet();                // No 40 kHz
    }
}

// Routine to send zero data burst
// Burst Timing is 24 * 0.025uS = 600uS
// Quiet Timing is 24 * 0.025uS = 600uS
void Data_is_Zero()
{
    for (int i=1; i <= 24; i++){
      burst();                // 40 kHz burst
    }
    for (int i=1; i <= 24; i++){
      quiet();                // No 40 kHz 
    }
}

Any assistance would be greatly appreciated.

My advice is to first get the keypad working with a simple test sketch separate from the rest of your code. You may be able to use one of the examples included with the Keypad library(File > Examples > Keypad). The test sketch would just print the pressed key to the Serial Monitor. Save the test sketch to use as a test if you need to troubleshoot the keypad later. Once you have that working it will be much easier to incorporate the working keypad code into your project.