Hello! I am making an LED watch with an Arduino and ultimately, one of my ATtiny 44A processors. It only has one green digit, is common cathode,and has one function: scroll time. The whole setup uses 9 pins. one for the button and 8 for the display.I would like it to display time in the order of the first digit of the hour, the second digit of the hour, the first digit of the minute, and the last digit of the minute in a 24 hour format. So I mashed together two example codes and I want them to work together. I found a code to display different digits on the seven segment (digits 0-9) and an example code for the time library where you can set the code using a UNIX time stamp with the serial port. I have the codes working independently, but now I would like it to display the time when I press the button. If you think that you can help out it would be much appreciated.
#include <Time.h>
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by Unix time_t as ten ASCII digits
#define TIME_HEADER 'T' // Header tag for serial time sync message
#define TIME_REQUEST 7 // ASCII bell character requests a time sync message
// T1262347200 //noon Jan 1 2010
const int buttonPin = 2;
int buttonState = 0;
byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
{ 0,1,1,0,0,0,0 }, // = 1
{ 1,1,0,1,1,0,1 }, // = 2
{ 1,1,1,1,0,0,1 }, // = 3
{ 0,1,1,0,0,1,1 }, // = 4
{ 1,0,1,1,0,1,1 }, // = 5
{ 1,0,1,1,1,1,1 }, // = 6
{ 1,1,1,0,0,0,0 }, // = 7
{ 1,1,1,1,1,1,1 }, // = 8
{ 1,1,1,0,0,1,1 } // = 9
};
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
writeDot(0); // start with the "dot" off
}
void writeDot(byte dot) {
digitalWrite(9, dot);
}
void sevenSegWrite(byte digit) {
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}
void loop(){
if(Serial.available() )
{
processSyncMessage();
}
if(timeStatus() == timeNotSet)
Serial.println("waiting for sync message");
else
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
void processSyncMessage() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of header & 10 ASCII digits
char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
c = Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
setTime(pctime); // Sync Arduino clock to the time received on the serial port
}
}
}
void leddisplay(){
//addition to BOTH of the codes; a sort of marriage between them.
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
//here the time would convert to the 7 segment display
}
}
Thanks!