I need a little help for a club project

Hello,

I have created my following code for my club.
Now I do not want to display on the LCD but on my 6 digit 7 segment display times.
Each segment is operated at a 74HC595 shift register.

I thank you for the help.

We have attached a photo of the display.

Thanks in advance

Markus1995

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // LCD keypad shield

#define STARTBUTTON 50
#define STOPBUTTON 51

boolean timerActive[2];   // 2 Timer aktiv true/false
long timerStartTime[2];   // 2 Startzeiten in Millisekunden
long timerTime[2];        // 2 Zählerstände in Millisekunden
byte nextStartTimer;
byte nextStopTimer;

void eingabe()
{
  static byte startButtonState;
  static byte stopButtonState;
  byte state;
  state=!digitalRead(STARTBUTTON);
  if (state==HIGH && startButtonState==LOW)
  {
    if (timerActive[nextStartTimer]==false)
    {
      timerActive[nextStartTimer]=true;
      timerStartTime[nextStartTimer]=millis();
      nextStartTimer=(nextStartTimer+1)%2;
    }
  }
  startButtonState=state;
  state=!digitalRead(STOPBUTTON);
  if (state==HIGH && stopButtonState==LOW)
  {
    if (timerActive[nextStopTimer]==true)
    {
      timerActive[nextStopTimer]=false;
      nextStopTimer=(nextStopTimer+1)%2;
    }
  }
  stopButtonState=state;
//  delay(5);    // Zeit zum Entprellen (entfällt bei "langsamer" loop-Funktion
}

void verarbeitung()
{
  for (int i=0;i<2;i++) // Zeiten für beide Timer aktualisieren
  {
    if (timerActive[i]==true) timerTime[i]=millis()-timerStartTime[i];
  }
}

void ausgabe()
{
  int hour,minute,second, fraction;
  char timebuf[17];
  boolean markerActive=false;
  int i=(millis()/3000)%2; // Welcher Timer ist zur Darstellung dran?
  if (timerActive[0]!=timerActive[1]) // Ist nur ein Timer aktiv?
  { // in dem Fall nur den inaktiven Timer darstellen
    if (timerActive[0]) i=1; else i=0; // der stehende (andere) Timer wird angezeigt
    markerActive=true;
  }

    unsigned long time=timerTime[i];
    fraction=(time%1000)/10; // Millisekunden/10 = Hundertstel
    time=time/1000;
    second=time%60;
    time=time/60;
    minute=time%60;
    hour=time/60;
    sprintf(timebuf,"%02d:%02d:%02d,%02d",hour,minute,second,fraction);
    lcd.setCursor(0,0);
    lcd.print(i+1);
    lcd.print("= ");
    lcd.print(timebuf);
    if (markerActive && (millis()/500)%2==0)
      lcd.print(" *");
    else  
      lcd.print("  ");
}


void setup()
{
  pinMode(STARTBUTTON,INPUT_PULLUP);
  pinMode(STOPBUTTON,INPUT_PULLUP);
  lcd.begin(16, 2);                // start the LCD library
}

void loop()
{
  eingabe();
  verarbeitung();
  ausgabe();
}

So what problem are you having?

I have no idea how I can spend time on the timer Shiftout and to be the times displayed in the change.

Or better would be if only the standing time is displayed.

have no one an Idea?

Markus1995:
have no one an Idea?

I couldn't figure out what you're asking with this sentence:

I have no idea how I can spend time on the timer Shiftout and to be the times displayed in the change.

how can I display my 2 times in exchange for my 7 segment displays?

I would prefer to leave only the standing of two times Show on the 7 segment display

Could you now figure out what i mean??

Markus1995:
Could you now figure out what i mean??

You may have better luck on the international forums.

I don't want to display the times on the LCD Display.

I want to display the times on my seven Segment Display.

XD

Check this out
http://playground.arduino.cc/Main/SevenSegmentLibrary

HI,

this library doesn't work, because I have 6 74HC595 Shift regitser.

My intent was to give you a starting point, not "plug and play", sorry.
It looks as this is more on how to use / hook-up shift register that how to program 7 segment display.
Personally, unless it is a school required exercise to use shift register, I am sure Arduino would do same job multiplexing the display with proper "power / driver " interface. Depending on the type / requirements of the actual display.

HI,

I think this code is closer the solution.

but it doesnt work

#define STARTBUTTON 6
#define STOPBUTTON 7
byte running = 0;
byte display_update = 0; // flag to indicate shiftouts are to occur

unsigned long currentmicros = 0;
unsigned long previousmicros = 0;
unsigned long interval = 10000;
unsigned long elapsedmicros = 0;

byte latchpin = 8; // connect to pin 12 on the 74HC595
byte clockpin = 52;  // connect to pin 11 on the 74HC595
byte datapin = 51; // connect to pin 14 on the 74HC595

int segdisp[10] = {
  63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers
//The above numbers light up different segments of a digit

boolean timerActive[2];   // 2 Timer aktiv true/false
long timerStartTime[2];   // 2 Startzeiten in Millisekunden
long timerTime[2];        // 2 Zählerstände in Millisekunden
byte nextStartTimer;
byte nextStopTimer;
int time_update = 0;// added new flag


int Minutenzehner;
int Minuten;
int Sekundenzehner;
int Sekunden;
int Millisekunden;
int Hundertstel;

void eingabe()
{
  static byte startButtonState;
  static byte stopButtonState;
  byte state;
  state=!digitalRead(STARTBUTTON);
  if (state==HIGH && startButtonState==LOW)
  {
    if (timerActive[nextStartTimer]==false)
    {
      timerActive[nextStartTimer]=true;
      timerStartTime[nextStartTimer]=millis();
      nextStartTimer=(nextStartTimer+1)%2;
    }
  }
  startButtonState=state;
  state=!digitalRead(STOPBUTTON);
  if (state==HIGH && stopButtonState==LOW)
  {
    if (timerActive[nextStopTimer]==true)
    {
      timerActive[nextStopTimer]=false;
      nextStopTimer=(nextStopTimer+1)%2;
    }
  }
  stopButtonState=state;
//  delay(5);    // Zeit zum Entprellen (entfällt bei "langsamer" loop-Funktion
}

void verarbeitung()
{
  for (int i=0;i<2;i++) // Zeiten für beide Timer aktualisieren
  {
    if (timerActive[i]==true) timerTime[i]=millis()-timerStartTime[i];
  }
  
    // when started flag is pressed, start counting in 10mS increments
  if (timerActive[1] == 1){
    currentmicros = micros();  // read the time.
    elapsedmicros = currentmicros - previousmicros;

    if (elapsedmicros >= interval) // 10 milliseconds have gone by
    {
      previousmicros  = previousmicros + elapsedmicros;  // save the time for the next comparison
      time_update = 1; // set flag to shift out the new time
    }

    if (time_update == 1){  // no updating if not at 10ms interval, skip this whole section
      // increment the counters, roll as needed, shift the digits out

      time_update = 0; // reset for next pass thru
      display_update = 1;
}
  }
}
void ausgabe()
{
  int hour,minute,second, fraction;
  char timebuf[17];
  boolean markerActive=false;
  int i=(millis()/3000)%2; // Welcher Timer ist zur Darstellung dran?
  if (timerActive[0]!=timerActive[1]) // Ist nur ein Timer aktiv?
  { // in dem Fall nur den inaktiven Timer darstellen
    if (timerActive[0]) i=1; else i=0; // der stehende (andere) Timer wird angezeigt
    markerActive=true;
  }

    unsigned long time=timerTime[i];
    fraction=(time%1000)/10; // Millisekunden/10 = Hundertstel
    time=time/1000;
    second=time%60;
    time=time/60;
    minute=time%60;
    hour=time/60;
    sprintf(timebuf,"%02d:%02d:%02d,%02d",hour,minute,second,fraction);
    
    Minutenzehner = minute/10;  //Zehner Minuten
    Minuten = minute%10;  //Minuten
    Sekundenzehner = second/10;  //Zehner Sekunden
    Sekunden = second%10;  //Sekunden
    Millisekunden = time;  //Millisekunden
    Hundertstel = fraction;  //Hundertstel
    
      if (display_update == 1){
    
        digitalWrite(latchpin, LOW); // send the digits down to the shift registers!
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[Minutenzehner]); // print the upper minutes digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[Minuten]); // print the lower sinutes digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[Sekundenzehner]); // print the upper seconds digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[Sekunden]); // print the lower seconds digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[Millisekunden]);     // print the tenths digit
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[Hundertstel]); // print the hundredths digit
   
    digitalWrite(latchpin, HIGH);
    display_update = 0; // reset for next pass thru
      }

    //if (markerActive && (millis()/500)%2==0)
      //lcd.print(" *");
    //else  
      //lcd.print("  ");
}


void setup()
{
  pinMode(STARTBUTTON,INPUT_PULLUP);
  pinMode(STOPBUTTON,INPUT_PULLUP);
  Serial.begin (9600);
}

void loop()
{
  eingabe();
  verarbeitung();
  ausgabe();
}

but it doesnt work

It does something. You expect it to do something. All we can tell from this lame statement is that what it does is not what you want.

that's true :slight_smile:

at the beginning of the segments light up briefly, but he does not count any more and they remain segments of time. That's the problem.

Hello again,

I now have a new Sktech.

The display on the seven segment display works now. smiley

Unfortunately, he starts I think both times because he always changes the first digit between one and two.

He also no longer sets the time to 0 after you and then presses pause start.
He simply goes back to where he has stopped.

Sketch is annexed

Thanks in advance for your help

MfG

Markus1995

Stoppuhr_Markus_20_09_2014-140921a.zip (3.57 KB)

Hello again,

I have now as far as hinbekommen the stopwatch with the 2 times myself :slight_smile:

Unfortunately, work output, which is located in the Sketch under f_display not 100%.

What I lack, or what I is not got done, I would like the time is stopped at the time show.

So not the time the degree is still running show, but the stopped

Thank you apologize in advance

Markus1995

boolean timerActive[2];   // 2 Timer aktiv true/false
long timerStartTime[2];   // 2 Startzeiten in Millisekunden
long timerTime[2];        // 2 Zählerstände in Millisekunden
byte nextStartTimer;
byte nextStopTimer;
#define STARTBUTTON 6
#define STOPBUTTON 5

static byte startButtonState;
static byte stopButtonState;

byte state;
byte state1;

int segdisp[10] = {
  63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers
//The above numbers light up different segments of a digit

unsigned long currentmicros1;
unsigned long previousmicros1;
unsigned long interval = 10000;
unsigned long elapsedmicros1;

unsigned long elapsedmicros2;
unsigned long currentmicros2;
unsigned long previousmicros2;

byte latchpin = 8; // connect to pin 12 on the 74HC595
byte clockpin = 52; // connect to pin 11 on the 74HC595
byte datapin = 51; // connect to pin 14 on the 74HC595

byte hundredths1;
byte tenths1;
byte ones_seconds1;
byte tens_seconds1;
byte ones_minutes1;

byte hundredths2;
byte tenths2;
byte ones_seconds2;
byte tens_seconds2;
byte ones_minutes2;

byte start_button_state = 0;
byte start_button = 6;

byte stop_button_state = 0;
byte stop_button = 5;

byte running1 = 0;
byte running2 = 0;  // was 'started'

byte time_update1;// added new flag
byte display_update1; // flag to indicate shiftouts are to occur

byte time_update2;// added new flag
byte display_update2; // flag to indicate shiftouts are to occur

void setup()
{
  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);

  pinMode(start_button, INPUT);
  digitalWrite (start_button, HIGH); // enable pullup

  pinMode(stop_button, INPUT);
  digitalWrite (stop_button, HIGH); // enable pullup 
}

void loop()
{
  // when started flag is pressed, start counting in 10mS increments)
if (timerActive[0]==true){
     
    currentmicros1 = micros();  // read the time
    elapsedmicros1 = currentmicros1 - previousmicros1;

    if (elapsedmicros1 >= interval) // 10 milliseconds have gone by
    {
      previousmicros1  = previousmicros1 + elapsedmicros1;  // save the time for the next comparison
      time_update1 = 1; // set flag to shift out the new time
    }

    if (time_update1 == 1){  // no updating if not at 10ms interval, skip this whole section
      // increment the counters, roll as needed, shift the digits out

      time_update1 = 0; // reset for next pass thru

      hundredths1 = hundredths1 +1;

      if (hundredths1 == 10){
        hundredths1 = 0;
        tenths1 = tenths1 +1;
      }

      if (tenths1 == 10){
        tenths1 = 0;
        ones_seconds1 = ones_seconds1 +1;
        //Serial.print (ones_seconds, DEC);
        //Serial.print (" ");
      }

      if (ones_seconds1 == 10){
        ones_seconds1 = 0;
        //Serial.println ("");
        hundredths1 = hundredths1 +3;   // Speed up the clock!
        tens_seconds1 = tens_seconds1 +1;
      }

      if (tens_seconds1 == 6){
        tens_seconds1 = 0;
        hundredths1 = hundredths1 +6;   // Speed up the clock!
        ones_minutes1 = ones_minutes1 +1;
      }

      if (ones_minutes1 == 10){
        ones_minutes1 = 0;
      }
      
      display_update1 = 1;

    }  // end if time to be updated

  }  // end of if-started[]
      
  
if (timerActive[1]==true){
        
    currentmicros2 = micros();  // read the time
    elapsedmicros2 = currentmicros2 - previousmicros2;

    if (elapsedmicros2 >= interval) // 10 milliseconds have gone by
    {
      previousmicros2  = previousmicros2 + elapsedmicros2;  // save the time for the next comparison
      time_update2 = 1; // set flag to shift out the new time
    }

    if (time_update2 == 1){  // no updating if not at 10ms interval, skip this whole section
      // increment the counters, roll as needed, shift the digits out

      time_update2 = 0; // reset for next pass thru

      hundredths2 = hundredths2 +1;

      if (hundredths2 == 10){
        hundredths2 = 0;
        tenths2 = tenths2 +1;
      }

      if (tenths2 == 10){
        tenths2 = 0;
        ones_seconds2 = ones_seconds2 +1;
        //Serial.print (ones_seconds, DEC);
        //Serial.print (" ");
      }

      if (ones_seconds2 == 10){
        ones_seconds2 = 0;
        //Serial.println ("");
        hundredths2 = hundredths2 +3;   // Speed up the clock!
        tens_seconds2 = tens_seconds2 +1;
      }

      if (tens_seconds2 == 6){
        tens_seconds2 = 0;
        hundredths2 = hundredths2 +6;   // Speed up the clock!
        ones_minutes2 = ones_minutes2 +1;
      }

      if (ones_minutes2 == 10){
        ones_minutes2 = 0;
      }
      
      display_update2 = 1;

    }  // end if time to be updated

  }  // end of if-started[]
  
   state=!digitalRead(STARTBUTTON);
  if (state==HIGH && startButtonState==LOW)
  {
      if (timerActive[0]==false)
      {  hundredths1 = 0;
         tenths1 = 0;
         ones_seconds1 = 0;
         tens_seconds1 = 0;
         ones_minutes1 = 0;
      }
      
      if (timerActive[1]==false)
      {  hundredths2 = 0;
         tenths2 = 0;
         ones_seconds2 = 0;
         tens_seconds2 = 0;
         ones_minutes2 = 0;
      }
      
    if (timerActive[nextStartTimer]==false)
    {   
      timerActive[nextStartTimer]=true;
      timerStartTime[nextStartTimer]=millis();
      nextStartTimer=(nextStartTimer+1)%2;
    }
  }
  startButtonState=state;

  state1=!digitalRead(STOPBUTTON);
  if (state1==HIGH && stopButtonState==LOW)
  {
    if (timerActive[nextStopTimer]==true)
    {
      timerActive[nextStopTimer]=false;
      nextStopTimer=(nextStopTimer+1)%2;
    }
    if (timerActive[1]==false)
    {
      nextStartTimer=0;
      nextStopTimer=0;
    }
     delay(10);    // Zeit zum Entprellen (entfällt bei "langsamer" loop-Funktion)
  }
  stopButtonState=state1;

   int i=(millis()/3000)%2; // Welcher Timer ist zur Darstellung dran?
  // Wenn nur ein Timer aktiv zählt, und der andere Timer steht, wird stets der stehende Timer angezeigt
  if (timerActive[0]!=timerActive[1]) // Ist nur ein Timer aktiv?
  { // in dem Fall nur den inaktiven Timer darstellen
    if (timerActive[0]) i=1; else i=0; // der stehende (andere) Timer wird angezeigt
  }

  
 if (display_update1 == 1 && i==1 || display_update2 == 1 && i==1){
  digitalWrite(latchpin, LOW); // send the digits down to the shift registers!
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[1]);          // print car lane number
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes1]); // print the lower sinutes digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds1]); // print the upper seconds digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds1]); // print the lower seconds digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths1]);     // print the tenths digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths1]); // print the hundredths digit
  
  digitalWrite(latchpin, HIGH);
    display_update1 = 0; // reset for next pass thru
 }
    
     if (display_update2 == 1 && i==0 || display_update1 == 1 && i==0){
  digitalWrite(latchpin, LOW); // send the digits down to the shift registers!
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[2]);          // print car lane number
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes2]); // print the lower sinutes digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds2]); // print the upper seconds digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds2]); // print the lower seconds digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths2]);     // print the tenths digit
  shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths2]); // print the hundredths digit
  
  digitalWrite(latchpin, HIGH);
    display_update2 = 0; // reset for next pass thru
     }
}// end void loop

Stoppuhr_1-140924a.zip (3.18 KB)