Time lapse

From NYC Resistor Wiki
Jump to: navigation, search
  0 // DE-DP001 Interface Example for Arduino / ATMEGA168
  1 // Full of bugs =P
  2 // matt@nycresistor.com
  3 
  4 #define DATAOUT 11//MOSI
  5 #define SPICLOCK 13//sck
  6 #define DIMM 9//DIMM
  7 #define APP 4
  8 #define SHUT 3
  9 #define FOC 2
 10 
 11 byte numbers[9];
 12 
 13 int shotcount;
 14 
 15 char spi_transfer(volatile char data)
 16 {
 17   SPDR = data;
 18   //
 19   while (!(SPSR & (1<<SPIF)))
 20   {
 21   };
 22   return SPDR;
 23 }
 24 
 25 void setup()
 26 {
 27   byte i;
 28   byte clr;
 29   pinMode (DATAOUT, OUTPUT);
 30   pinMode (SPICLOCK, OUTPUT);
 31   pinMode (10, OUTPUT);
 32   pinMode (FOC, OUTPUT);
 33   pinMode (SHUT, OUTPUT);
 34   pinMode (APP, OUTPUT);
 35   pinMode (DIMM, OUTPUT);
 36   digitalWrite(DIMM, HIGH);
 37   
 38   numbers[0] = 0x3F;
 39   numbers[1] = 0x06;
 40   numbers[2] = 0x5B;
 41   numbers[3] = 0x4F;
 42   numbers[4] = 0x66;
 43   numbers[5] = 0x6D;
 44   numbers[6] = 0x7D;
 45   numbers[7] = 0x07;
 46   numbers[8] = 0x7F;
 47   numbers[9] = 0x6F;
 48   
 49   SPCR = 0b01010010;
 50   clr = SPDR;
 51   delay(32);
 52 }
 53 
 54 byte write_led(int value1 , int value2, int value3, int value4)
 55 {
 56   digitalWrite(DIMM,LOW);
 57   //2 byte opcode
 58  spi_transfer(value1);
 59  spi_transfer(value2);
 60  spi_transfer(value3);
 61  spi_transfer(value4);
 62   delay(36);
 63   digitalWrite(DIMM,HIGH); //release chip, signal end transfer
 64 
 65 }
 66 
 67 byte cam_shot() {
 68   digitalWrite(FOC, HIGH);
 69   delay(10);
 70   digitalWrite(FOC, LOW);
 71   delay(10);
 72   digitalWrite(SHUT, HIGH);
 73   delay(2);
 74   digitalWrite(SHUT, LOW);
 75   shotcount++;
 76 }
 77   
 78 byte display(int count) {
 79   byte first_digit;
 80   byte second_digit;
 81   byte third_digit;
 82   byte fourth_digit;
 83   
 84   int newcount;
 85   
 86   int bucket = count / 1000;
 87   newcount = count - (bucket * 1000);
 88   first_digit = numbers[bucket];
 89   
 90   bucket = newcount / 100;
 91   newcount = newcount - (bucket * 100);
 92   second_digit = numbers[bucket];
 93   
 94   bucket = newcount / 10;
 95   newcount = newcount - (bucket * 10);
 96   third_digit = numbers[bucket];
 97   
 98   bucket = count % 10;
 99   fourth_digit = numbers[bucket];
100 
101   write_led(fourth_digit, third_digit, second_digit, first_digit);
102 }
103 
104 void loop() 
105 {
106   cam_shot();
107   display(shotcount);
108   delay(10000); // Display refresh  
109 }