Go Down

Topic: 7 segment Display Watch (Read 2 times) previous topic - next topic

CrossRoads

I would show the digits as part of this
Code: [Select]

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();
}

Make an array of number fonts, drive the segments from that array.
Every 4 seconds, update a digit.  Display second only when button is pressed.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Flyingchainsaw

Ok! thanks for the reply! The button would display the time when pressed tho. so the button would activate the loop, instead of seconds, to save battery life. And how would I set up an array?

CrossRoads

The array part is easy. Assuming you want a 1 to turn on a segment:
Code: [Select]

// pre-setup code
// array of segments to turn on
//B = binary, with bits= decimal point-g-f-e-d-c-b-a
segmentArray[] = {
B00111111, // 0       a
B00000110, // 1    f      b
B01101011, // 2       g
B01001111, // 3    e     c
B01100110, // 4       d
B01101101, // 5
B01011111, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
};
// array of pins to turn on
byte pinArray[] = {2,3,4,5,6,7,8,9};
// 9 = Decimal point, 8=g, 7=f, 6=e,5=d, 4=c, 3=b, 2=a


Code: [Select]

// loop code, or a function
// display a digit
// assumes numberToDisplay is assigned/passed on:
maskBit = 0x01; // masks off all but segment A to start
for (x = 0; x<8; x=x+1){
// for x=0: write pin 2 with (B00000001 & numberToDisplay) to turn on/off segment A
// then 3 with B00000010 & numberToDisplay for segment B, etc.
digitalWrite (pinArray[x], (segmentArray[numberToDisplay] & maskBit) );
maskBit = maskBit <1; // move the bit 1 left to mask for next segment
}


Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up