#include <toneAC.h>
#include <SevSeg.h>

// credits to https://www.circuitbasics.com/arduino-7-segment-display-tutorial/


const byte SS_D1_PIN = 7;
const byte SS_A_PIN = 6;
const byte SS_F_PIN = 5;
const byte SS_D2_PIN = 4;
const byte SS_D3_PIN = 3;
const byte SS_B_PIN = 2;
const byte SS_E_PIN = A0;
const byte SS_D_PIN = A1;
const byte SS_DP_PIN = A2;
const byte SS_C_PIN = A3;
const byte SS_G_PIN = A4;
const byte SS_D4_PIN = A5;
SevSeg sevseg;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Starting Seven Segment Display Test");
  byte numDigits = 4;  
  byte digitPins[] = {SS_D1_PIN, SS_D2_PIN, SS_D3_PIN, SS_D4_PIN}; // D1, D2, D3, D4 When they are low, the value on the segments is displayed
  byte segmentPins[] = {SS_A_PIN, SS_B_PIN, SS_C_PIN, SS_D_PIN, SS_E_PIN, SS_F_PIN, SS_G_PIN, SS_DP_PIN}; // DP, and segments ABCDEFG, by turning some on and others off, you can display different numbers
  bool resistorsOnSegments = 0; 
  byte hardwareConfig = COMMON_CATHODE; // You may need to change this if your display is COMMON ANODE
  bool updateWithDelays = false;
  bool leadingZeros = true;
  bool disableDecPoint = false;

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
  updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(60);
}

void loop() {
  // put your main code here, to run repeatedly:
  int thetime = (millis()/10)%10000;
  if(thetime == 0){
    toneAC(440, 10, 1000);
    }
  sevseg.setNumber(thetime,2); // set the characters/numbers to display.
  sevseg.refreshDisplay();
}
