Here is the clock I am trying to recreate. The author uses a Pickaxe chip and Pickaxe editor to program the chip. I tried to recreate on the Arduino, the basic code he wrote for the pickaxe chip. The pendulum is the time keeper and the goal is to alternately pulse the motor coil of an analog clock.
I have the pendulum working nicely but can't seem to get the alternating pulses. I'm using LEDs to observe whether I am getting the alternating pulses and am not getting them. Thanks to all for the help
Here is the code for an Arduino driven analog clock. I'm trying to regulate it with the pendulum circuit.
type or paste code here
Clock Tick Demonstration
//
// By Matt Mets, completed in 2008
//
// This code is released into the public domain. Attribution is appreciated.
//
// This is a demonstration on how to control a cheapo clock mechanism with an Arduino.
// The clock mechanism works by using an electromagnet to pull a little fixed magnet,
// similar to how a DC motor works. To control this with the Arduino, we need to hook a
// wire up to each side of the electromagnet (disconnect the exisiting clock circuity if
// possible). Then, hook each of the wires to pins on the Arduino. I chose pins 2 and 3
// for my circuit. It is also a good idea to put a resistor (I chose 500 ohms) in series
// (between one of the wires and an Arduino pin), which will limit the amount of current
// that is applied. Once the wires are hooked up, you take turns turning on one or the
// other pin momentarily. Each time you do this, the clock 'ticks' and moves forward one
// second. I have provided a doTick() routine to do this automatically, so it just needs
// to be called each time you want the clock to tick.
//
////// Board Setup /////////////////////////////////////////////////////////////////////////
extern unsigned long timer0_overflow_count;
int clockA = 2; // Set these to the pin numbers you have attached the clock wires
int clockB = 3; // to. Order is not important.
int tickPin = clockA; // This keeps track of which clock pin should be fired next.
// Initialize the IO ports
void setup()
{
pinMode(clockA, OUTPUT);
pinMode(clockB, OUTPUT);
digitalWrite(clockA, LOW);
digitalWrite(clockB, LOW);
Serial.begin(9600);
}
// Move the second hand forward one position (one second on the clock face).
void doTick() {
// Energize the electromagnet in the correct direction.
digitalWrite(tickPin, HIGH);
delay(10);
digitalWrite(tickPin, LOW);
// Switch the direction so it will fire in the opposite way next time.
if (tickPin == clockA)
{
tickPin = clockB;
} else {
tickPin = clockA;
}
}
// Main loop
void loop()
{
unsigned long startTime = millis();
unsigned long temp;
// Pretend to be a regular clock, and tick once a second.
while (true)
{
startTime += 1000;
// Wait until a second has passed. Note that this will do ugly things when millis()
// runs over, so we only have about 9 hours before this version will stop working.
while (startTime - millis() > 0) {}
doTick();
}