1hp: Voltmeter Clock

This is the first edition of a series I’m calling “1 Hour Projects” or “1HP” for short.

I made this voltmeter clock using a simple script that varies an Arduino PWM out a fraction of its maximum voltage (5v) with each second. Every 8 seconds it does a recall of the current time by first ticking over to the hour and then the minute.

The whole thing was programmed in Processing. You can find my code below.

[code]/*
Voltmeter Clock – Code by Matthew Borgatti ***http://sinbox.org***

*/

int secondValue = 0;
int minuteValue = 0;
int hourValue = 0;
int clockPin = 9; //The input lead for the voltmeter. Connect the other lead coming from the meter to ground
int voltRange = 125; //voltRange defines the maximum operating voltage of your meter (max = 255 ~5v)
int voltVal = voltRange / 60;
int minutes = voltRange / 60;
int hours = voltRange / 12;
int value = 0; //value is a container for the current voltage
int switch1 = 10; //The input pin for the minute setting switch
int switch2 = 11; //The input pin for the hour setting switch
int pingPong = 0; //Setting pingPong to 1 will have the second hand pingpong between 0 and 255

void setup()
{
Serial.begin(9600);
}

void loop()
{
for(value = 0 ; value <= voltRange; value += voltVal) // fade in (from min to max) { secondValue += 1; if(secondValue % 10 == 0) { int curHours = hours * hourValue; analogWrite(clockPin, curHours); delay(1000); value += voltVal; int curMinutes = minutes * minuteValue; analogWrite(clockPin, curMinutes); delay(1000); value += voltVal; secondValue += 2; } if(secondValue > 59)
{
secondValue = 0;
minuteValue += 1;
}
if(minuteValue > 59)
{
minuteValue = 0;
hourValue += 1;
}
if(hourValue > 11)
{
hourValue = 0;
}
if(value >= voltRange)
{
value = 0;
}
analogWrite(clockPin, value); // sets the value (range from 0 to 255)
delay(1000); // waits for 30 milli seconds to see the dimming effect
}
for(value = voltRange; value >=0 && pingPong == 1; value -= voltVal) // fade out (from max to min)
{
secondValue += 1;
if(secondValue % 10 == 0)
{
int curHours = hours * hourValue;
analogWrite(clockPin, curHours);
delay(1000);
value += voltVal;
int curMinutes = minutes * minuteValue;
analogWrite(clockPin, curMinutes);
delay(1000);
value += voltVal;
secondValue += 2;
}
if(secondValue > 59)
{
secondValue = 0;
minuteValue += 1;
}
if(minuteValue > 59)
{
minuteValue = 0;
hourValue += 1;
}
if(hourValue > 11)
{
hourValue = 0;
}
analogWrite(clockPin, value); // sets the value (range from 0 to 255)
delay(1000); // waits for 30 milli seconds to see the dimming effect
}
}[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *