Aduino Watch Project

Hey everyone I am back with this wristwatch project I am working on. So far the code works by flashing each digit of the current time in 12 hour format with AM and PM, it also removes the superfluous zero from AM time. Eventually I would like to run this on an ATtiny85 so I am trying to get the code to run with fewer lines but I am a newbie. My current issues that I would like to add onto the matrix which defines the pixel logic three things for now:
the letter A, P, and a blank array (all zeros) for clearing the display.

boolean digits [13] [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
                           1, 1, 1, 0, 1, 1, 1,    // A
                           1, 1, 0, 0, 1, 1, 1,    // P
                           0, 0, 0, 0, 0, 0, 0, }; // null

The I tried call out the three rows at the bottom the same way as numbers:

displayDigit(A);
displayDigit(P);
displayDigit(null);

I know that this is incorrect use of these functions, and it obviously did not work, but I am not sure how to implement what I want. I think it has to do with 'string()' but I don't know how.

Here is the complete working code for my Wokwi simulation:

/*
Written by Austin Fox for a simple low power digital wristwatch
to operate simply press the pushbutton and the current 12-hour time will flash sequentially

for wiring in Wokwi.com paste the following into diagram.json:

{
  "version": 1,
  "author": "Austin Fox",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-uno", "id": "uno", "top": 0, "left": 0, "attrs": {} },
    {
      "type": "wokwi-7segment",
      "id": "sevseg1",
      "top": 61.86,
      "left": 501.89,
      "attrs": { "color": "white", "common": "cathode" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": 78.35,
      "left": 755.51,
      "attrs": { "color": "BL" }
    },
    { "type": "wokwi-resistor", "id": "r1", "top": 11.34, "left": 572.35, "attrs": {} },
    { "type": "wokwi-resistor", "id": "r2", "top": 36.61, "left": 571.72, "attrs": {} },
    { "type": "wokwi-resistor", "id": "r3", "top": 35.74, "left": 415.68, "attrs": {} },
    { "type": "wokwi-resistor", "id": "r4", "top": 12.67, "left": 416.82, "attrs": {} },
    { "type": "wokwi-resistor", "id": "r5", "top": 154.2, "left": 424.05, "attrs": {} },
    { "type": "wokwi-resistor", "id": "r6", "top": 178.06, "left": 425.89, "attrs": {} },
    { "type": "wokwi-resistor", "id": "r7", "top": 157.78, "left": 578.53, "attrs": {} },
    { "type": "wokwi-resistor", "id": "r8", "top": 183.15, "left": 580.24, "attrs": {} },
    { "type": "wokwi-ds1307", "id": "rtc1", "top": 289.42, "left": 275.99, "attrs": {} }
  ],
  "connections": [
    [ "r5:2", "sevseg1:E", "green", [ "v-0.34", "h24.81" ] ],
    [ "sevseg1:D", "r6:2", "green", [ "v0" ] ],
    [ "sevseg1:C", "r7:1", "green", [ "v0" ] ],
    [ "sevseg1:G", "r3:2", "green", [ "v0" ] ],
    [ "sevseg1:F", "r4:2", "green", [ "v0" ] ],
    [ "sevseg1:A", "r1:1", "green", [ "v0" ] ],
    [ "sevseg1:B", "r2:1", "green", [ "v0" ] ],
    [ "uno:GND.2", "r8:1", "black", [ "v47.38", "h366.87", "v-59.81" ] ],
    [ "uno:5V", "rtc1:5V", "red", [ "v0" ] ],
    [ "uno:GND.2", "rtc1:GND", "black", [ "v0" ] ],
    [ "rtc1:SDA", "uno:A4", "green", [ "h0" ] ],
    [ "rtc1:SCL", "uno:A5", "green", [ "h0" ] ],
    [ "r8:2", "btn1:2.r", "green", [ "v-0.02", "h209.95", "v-77.97" ] ],
    [ "uno:5V", "btn1:1.r", "red", [ "v69.31", "h714.16", "v-174.54" ] ],
    [ "r6:1", "uno:2", "green", [ "v0.04", "h-135.09", "v-203.33", "h-77.93" ] ],
    [ "r5:1", "uno:3", "green", [ "v-0.29", "h-109.06", "v-201.54", "h-85.09" ] ],
    [ "r3:1", "uno:4", "green", [ "v-0.06", "h-75.61", "v-106.59", "h-130.78" ] ],
    [ "r4:1", "uno:5", "green", [ "v-0.28", "h-52.57", "v-105.7", "h-175.56" ] ],
    [ "r1:2", "uno:6", "green", [ "v-0.2", "h32.78", "v-128.07", "h-470.29" ] ],
    [ "r2:2", "uno:7", "green", [ "v0.14", "h58", "v-176.23", "h-495.91" ] ],
    [ "r7:2", "uno:8", "green", [ "v-0.51", "h76.34", "v-318.39", "h-575.35" ] ],
    [ "btn1:2.l", "uno:9", "green", [ "h-18.57", "v-291.54", "h-564.07" ] ],
    [ "uno:GND.3", "sevseg1:COM.1", "black", [ "v24.72", "h310.55" ] ]
  ]
}

  A  
F   B
  G
E   C
  D

*/

#include "RTClib.h"
RTC_DS1307 rtc;
const int buttonPin = 9;  //user input
int buttonState = 0;      //remove uncertainty
int8_t pinSegA = 6;       //7-segment display input pins
int8_t pinSegB = 7;       //7-segment display input pins
int8_t pinSegC = 8;       //7-segment display input pins
int8_t pinSegD = 2;       //7-segment display input pins
int8_t pinSegE = 3;       //7-segment display input pins
int8_t pinSegF = 5;       //7-segment display input pins
int8_t pinSegG = 4;       //7-segment display input pins
// Segment                 a  b  c  d  e  f  g     // Digit
boolean 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 () {
  if (! rtc.begin()) {2;   //RTC check
    abort();
  }
  pinMode (pinSegA, OUTPUT);  //IO definitions
  pinMode (pinSegB, OUTPUT); 
  pinMode (pinSegC, OUTPUT);  
  pinMode (pinSegD, OUTPUT); 
  pinMode (pinSegE, OUTPUT);  
  pinMode (pinSegF, OUTPUT);  
  pinMode (pinSegG, OUTPUT); 
  pinMode(buttonPin, INPUT);  
}
void displayDigit(uint8_t digit)
{
  digitalWrite(pinSegA, digits[digit][0]);  //assigns numerals to the matrix
  digitalWrite(pinSegB, digits[digit][1]);
  digitalWrite(pinSegC, digits[digit][2]);
  digitalWrite(pinSegD, digits[digit][3]);
  digitalWrite(pinSegE, digits[digit][4]);
  digitalWrite(pinSegF, digits[digit][5]);
  digitalWrite(pinSegG, digits[digit][6]);
  delay(1100);
  digitalWrite(pinSegA, LOW); //clears any persistant lit segments (needed for code to work)
  digitalWrite(pinSegB, LOW);
  digitalWrite(pinSegC, LOW);
  digitalWrite(pinSegD, LOW);
  digitalWrite(pinSegE, LOW);
  digitalWrite(pinSegF, LOW);
  digitalWrite(pinSegG, LOW);
}
void loop () {
DateTime now = rtc.now();   //defines time in library
  int minutes = now.minute();   //defines minutes
  int tens = minutes / 10;    //parsing tens and ones place from minutes
  int ones = minutes % 10;
  int hours = now.hour();   //defines hours
  int tenss = hours / 10;   //parsing tens and ones place from hours
  int oness = hours % 10;
  int hoursss = hours - 12;   //variable for 12 hr time
buttonState = digitalRead(buttonPin);   //checks button high or low
if (buttonState == HIGH)     
{
  if (hours >= 12)    //12 hour time logic
  {
  displayDigit(hoursss);
  } 
  else if (hours < 12) 
  {
    if (tenss > 0) {      //removes zero from tens place so AM time only shows 3 digits
     displayDigit(tenss);
     delay(250);
    } 
    displayDigit(oness);
  }
        delay(250);
    digitalWrite(pinSegG, HIGH);    //shows hyphen to replace normal colon
        delay(500);
    digitalWrite(pinSegG, LOW);     //shows hyphen to replace normal colon
        delay(250);
    displayDigit(tens);
        delay(250);
    displayDigit(ones);
        delay(250);
    if (hours >= 12)                //diplays P for PM
    {
      digitalWrite(pinSegA, HIGH);
      digitalWrite(pinSegB, HIGH);
      digitalWrite(pinSegE, HIGH);
      digitalWrite(pinSegF, HIGH);
      digitalWrite(pinSegG, HIGH);  
    } else if (hours < 12) {        //displays A for AM
      digitalWrite(pinSegA, HIGH);
      digitalWrite(pinSegB, HIGH);
      digitalWrite(pinSegC, HIGH);
      digitalWrite(pinSegE, HIGH);
      digitalWrite(pinSegF, HIGH);
      digitalWrite(pinSegG, HIGH);
    }
    delay(1100);
    digitalWrite(pinSegA, LOW);
    digitalWrite(pinSegB, LOW);
    digitalWrite(pinSegC, LOW);
    digitalWrite(pinSegD, LOW);
    digitalWrite(pinSegE, LOW);
    digitalWrite(pinSegF, LOW);
    digitalWrite(pinSegG, LOW); 
}
}

13 posts were merged into an existing topic: ATTINY+ RS3231 Watch Project Help