This one dispenses holiday cheer, the 50ml type. Each day at a predetermined time 5:00pm the clock will tell the microcontroller it's time to drop a bottle. This goes on for the length of Advent.
Advent can have up to 28 days in the year. I'm planning on using inexpensive latches driven by MOSFETs. In order to do this I'm learned that daisy chaining SN74HC595's would give me the output pins I need. The parts aren't expensive.
The nip will be held in 4 rows and 7 columns. I've got the mechanical side worked out I thinks.
Folks, I took BASIC in high school. It's gonna be a tough project but I'd like to see it through. It's for my wife's sister. She's German Irish so she wants the outside to look like a church.
Now that all of that is out of the way, I had no idea what direction to go for the bottle holders. At 4 rows and 7 columns we have the pins we needs (daisy chaining the SN74HC595). I need a way to address these pins for two reasons I can see; one, i need a way to randomize the selection a little. Two, I need to have the pin go HIGH to drop the nip, then stay low so as not to pull too much current and burn it up.
I was thinking of using descriptive variables like R0C0 (row 0, column 0) so that I knew if I've have problems releasing the miniatures. Too close they could binds up on the way out. Still I could go up to R4C7. How would I assign a number for an easy randomization pick, and how do I bring the pin HIGH, and then ensure it's LOW.
It's a lot to take in. Took me three weeks to work out the bottle drop and two daisy chained SN74HC595s.
So you have a bottle dropping? That's great progress.
If you can daisy chain two shift registers, you can daisy chain four of them (do remember the decoupling caps - a 100 nF cap at the Vcc pin of every single shift register).
For the time: get an RTC, such as the DS3231, for accuracy and keeping the time in case of power loss. Use the TimeLib library to make working with time easy.
Happy building; at least you're well on time starting your project. Too often I see such questions pop up weeks or just days before the event...
For addressing the pins: 28 outputs, 28 bits, that fits comfortably in a long integer (a 32-bit variable). Then you can just address the individual bits (0-27 for the 28 days of the advent) as numbers. Set/clear the appropriate bit to switch on/off the output. Something like this:
unsigned long outputState;
byte bottleToTopple = random(28); // select random number 0-27.
bitSet(outputState, bottleToTopple); // Set the appropriate bit.
setState(outputState); // Set the shift register - you have to implement this function.
delay(1000); // Wait some time.
setState(0); // Set shift register - all outputs low.
Note: this may pick a bottle that's been used already, so as improvement you have to keep track of which bottles were used. Store that value in the EEPROM so you can recover after power loss.
The first page of the datasheet has a logic diagram.
You can see two columns of flipflops.
SER (14) feeds data into the first D-flipflop of the left column. The output of each flipflop in the left column goes to the input of the next flipflop below it. This is the main "shift" action of a shift register.
SERCLK (11) is connected to all clock inputs of the flipflops. On rising edges of the clock, the state of the D-flipflop changes to whatever is on the data input (i.e. SER).
RCLK (12) is connected to all clock inputs of the flipflops in the right column. The outputs of the right flipflops go to the outputs of the chip (QX). On rising edges of this clock line, the data from the shift flipflops (left) is latched into the output flipflops (right).
When SERCLR is low, it resets the shift flipflops to zero.
When OE (output enable) is low, the output buffers are enabled.
SER (serial data) is sometimes called Data, RCLK (register clock) is sometimes called ST_CP (storage register clock pin) or Latch, SERCLK is sometimes called SH_CP (shift register clock pin).
Usually, you connect SER to the MOSI pin of the Arduino's SPI interface, SERCLK to the CLK pin, and RCLK to any digital output pin (usually the SPI CS pin since it's an output anyway when you're using SPI in master mode).
You have to use SPI mode 0 (clock polarity 0, clock phase 0), this is the default mode.
This is the code I use to easily enable and disable outputs for driving LEDs, relays, steppers ...: SPI-Blink.ino