Need Code for My Time Machine (3 digit 7 segment display)

"Damn it Jim, I'm a Prop Builder not a programmer!..."

I am building a replica of the Remote control used by Doc Brown in Back To The Future (attached reference photo). I want it to light up and do cool stuff, SO I am integrating a Arduino into the build.

I have very little programming experience. I have figured out how to add a library to my sketch, upload the example code to my Arduino UNO and wire the i/o devices to it.

The Plan:
I have a 3digit 7 segment 12 pin display attached to the prop that will count up from 00.0 then stop on 88.0 The counting will be activated via the a toggle switch.

The prop will have a 9v battery that powers the arduino.
When the arduino powers on it will send 00.0 to the LED display and await further input.
Another switch will start the count up to 88.0 and take 8 seconds to do so. once the display hits 88.0 it holds that number until the arduino is turned off.

I have already wired the 3 digit display to the arduino and have a few pins left for the toggle switch.
Digital Pin 1, 2, and 5 (Attached Photo of the 3 digit display working)

I will attach the code I have so far which is a SevSeq Library that is currently allowing me to display and hold three numbers and a decimal point.

#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object

void setup() {
  byte numDigits = 3;   
  byte digitPins[] = {2, 3, 4};
  byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};

  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
  sevseg.setBrightness(90);
}

void loop() {
  static unsigned long timer = millis();
  static int deciSeconds = 0;
  
  if (millis() >= timer) {
    deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
    timer += 100; 
    if (deciSeconds == 10000) { // Reset to 0 after counting for 1000 seconds.
      deciSeconds=0;
    }
    sevseg.setNumber(deciSeconds, 1);
  }

  sevseg.refreshDisplay(); // Must run repeatedly
}

/// END ///

I am looking for help from a programmer who can write the necessary code to perform the functions stated above. let me know of any additional info you need for the project. I am happy to discuss yur rate for the work.

doc_radio_A.jpg

PM me :slight_smile: i can help

Bainesbunch:
PM me :slight_smile: i can help

Well that was of little help for the rest of us :confused:

Perhaps this might do the job. I put the switch on pin 5. You can't really use 0/1 because they are used by the serial - you have to disconnect them to upload a new sketch, and it's a bit of a pain.

#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object

const byte switchPin = 5; // putting the toggle switch on pin 5
int switchState = HIGH;

const int maxDeciSeconds = 880;
unsigned long timer = millis();
int deciSeconds = 0;

// it's kind of important that these arrays are not put on the stack.
byte numDigits = 3;  
byte digitPins[] = {2, 3, 4};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};

void setup() {
  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
  sevseg.setBrightness(90);

  switchState = HIGH;
  sevseg.blank();

  pinMode(switchPin, INPUT_PULLUP);
}

void loop() {
  sevseg.refreshDisplay(); // give sevseg a time slice

  int prevSwitchState = switchState;
  switchState = digitalRead(switchPin);

  if(switchState == LOW && prevSwitchState == HIGH) {
    // switch just came on. Start at zero
    
    deciSeconds = 0;
    sevseg.setNumber(deciSeconds, 1);
    timer = millis();
  }
  else if(switchState == HIGH && prevSwitchState == LOW) {
    // switch just went off. Blank the display
    sevseg.blank();
  }

  
  if(switchState == HIGH) {
    // switch is off. do nothing.  
  }
  else if(deciSeconds >= maxDeciSeconds) {
    // 88 seconds done. do nothing (leave the '88.0' on screen).  
  }
  else if(millis() - timer < 100) { // this is the correct pattern for timing with millis
    // not time to increment yet. Do nothing.
  }
  else {
    deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
    timer += 100; // +100 rather than =millis() because +100 is more accurate
    sevseg.setNumber(deciSeconds, 1);
  }

}

/// END ///