Time lapse

From NYC Resistor Wiki
// DE-DP001 Interface Example for Arduino / ATMEGA168
// Full of bugs =P
// [email protected]

#define DATAOUT 11//MOSI
#define SPICLOCK 13//sck
#define DIMM 9//DIMM
#define APP 4
#define SHUT 3
#define FOC 2

byte numbers[9];

int shotcount;

char spi_transfer(volatile char data)
{
  SPDR = data;
  //
  while (!(SPSR & (1<<SPIF)))
  {
  };
  return SPDR;
}

void setup()
{
  byte i;
  byte clr;
  pinMode (DATAOUT, OUTPUT);
  pinMode (SPICLOCK, OUTPUT);
  pinMode (10, OUTPUT);
  pinMode (FOC, OUTPUT);
  pinMode (SHUT, OUTPUT);
  pinMode (APP, OUTPUT);
  pinMode (DIMM, OUTPUT);
  digitalWrite(DIMM, HIGH);
  
  numbers[0] = 0x3F;
  numbers[1] = 0x06;
  numbers[2] = 0x5B;
  numbers[3] = 0x4F;
  numbers[4] = 0x66;
  numbers[5] = 0x6D;
  numbers[6] = 0x7D;
  numbers[7] = 0x07;
  numbers[8] = 0x7F;
  numbers[9] = 0x6F;
  
  SPCR = 0b01010010;
  clr = SPDR;
  delay(32);
}

byte write_led(int value1 , int value2, int value3, int value4)
{
  digitalWrite(DIMM,LOW);
  //2 byte opcode
 spi_transfer(value1);
 spi_transfer(value2);
 spi_transfer(value3);
 spi_transfer(value4);
  delay(36);
  digitalWrite(DIMM,HIGH); //release chip, signal end transfer

}

byte cam_shot() {
  digitalWrite(FOC, HIGH);
  delay(10);
  digitalWrite(FOC, LOW);
  delay(10);
  digitalWrite(SHUT, HIGH);
  delay(2);
  digitalWrite(SHUT, LOW);
  shotcount++;
}
  
byte display(int count) {
  byte first_digit;
  byte second_digit;
  byte third_digit;
  byte fourth_digit;
  
  int newcount;
  
  int bucket = count / 1000;
  newcount = count - (bucket * 1000);
  first_digit = numbers[bucket];
  
  bucket = newcount / 100;
  newcount = newcount - (bucket * 100);
  second_digit = numbers[bucket];
  
  bucket = newcount / 10;
  newcount = newcount - (bucket * 10);
  third_digit = numbers[bucket];
  
  bucket = count % 10;
  fourth_digit = numbers[bucket];

  write_led(fourth_digit, third_digit, second_digit, first_digit);
}

void loop() 
{
  cam_shot();
  display(shotcount);
  delay(10000); // Display refresh  
}