Count Down (2 Digits of 7-segments)

Count Down (2 Digits of 7-segments) © GPL3+

A simple time count (down) with 7-segments displays.

  • 1,014 views
  • 0 comments
  • 5 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
7-segment display
×1

About this project

I made this project to count down time to play a game "the game of words"!!! The players have 30 seconds to say a word started with a letter and end with another. If the time ends and he don't say a word he loose.

The code of this project is interesant because counts seconds but a the same time can display it quickly.

Code

CodeArduino
//******************************************************************************************************
// 2 Digits - 7 Segments
// Autor: Joao Pereira
// Email: joaodper@gmail.com
// Data: 05/02/2017
//
// Saidas para o lcd
int seg_a = 10; // ##AAA##
int seg_b = 11; // F#####B
int seg_c = 7;  // F#####B
int seg_d = 6;  // ##GGG##
int seg_e = 5;  // E#####C
int seg_f = 9;  // E#####C
int seg_g = 8;  // ##DDD##

int digit1 = 12;
int digit2 = 13;

int digito1 = 0;
int digito2 = 0;
int valor = 30;
int a = 0;

unsigned long previousMillis = 0;
const long interval = 1000;

const int  buttonPin = 2;
int buttonState = 0;

void setup() {
 pinMode(seg_a, OUTPUT);  
 pinMode(seg_b, OUTPUT);  
 pinMode(seg_c, OUTPUT);  
 pinMode(seg_d, OUTPUT);
 pinMode(seg_e, OUTPUT);
 pinMode(seg_f, OUTPUT);
 pinMode(seg_g, OUTPUT);
 pinMode(digit1, OUTPUT);
 pinMode(digit2, OUTPUT);

 pinMode(buttonPin, INPUT);
}

void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) {
    valor = 30;
  }
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    valor--;
  }
  
  digitalWrite(digit1, HIGH);  
  digitalWrite(digit2, LOW);
  digito1 = (valor%10);
  display(digito1);
  delay(10);
  digitalWrite(digit1, LOW);  
  digitalWrite(digit2, HIGH);
  digito2 = ((valor/10)%10);
  display(digito2);
  delay(10);
}

int display(int a) {
   switch(a){ 
   case 0: 
     digitalWrite(seg_a, LOW);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, LOW);
     digitalWrite(seg_e, LOW);
     digitalWrite(seg_f, LOW); 
     digitalWrite(seg_g, HIGH); 
   break;  
   case 1: 
     digitalWrite(seg_a, HIGH);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, HIGH);
     digitalWrite(seg_e, HIGH);
     digitalWrite(seg_f, HIGH); 
     digitalWrite(seg_g, HIGH); 
   break;
   case 2: 
     digitalWrite(seg_a, LOW);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, HIGH); 
     digitalWrite(seg_d, LOW);
     digitalWrite(seg_e, LOW);
     digitalWrite(seg_f, HIGH); 
     digitalWrite(seg_g, LOW); 
   break;
   case 3: 
     digitalWrite(seg_a, LOW);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, LOW);
     digitalWrite(seg_e, HIGH);
     digitalWrite(seg_f, HIGH); 
     digitalWrite(seg_g, LOW); 
   break;
   case 4: 
     digitalWrite(seg_a, HIGH);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, HIGH);
     digitalWrite(seg_e, HIGH);
     digitalWrite(seg_f, LOW); 
     digitalWrite(seg_g, LOW); 
   break;   
   case 5: 
     digitalWrite(seg_a, LOW);  
     digitalWrite(seg_b, HIGH); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, LOW);
     digitalWrite(seg_e, HIGH);
     digitalWrite(seg_f, LOW); 
     digitalWrite(seg_g, LOW); 
   break;
   case 6: 
     digitalWrite(seg_a, HIGH);  
     digitalWrite(seg_b, HIGH); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, LOW);
     digitalWrite(seg_e, LOW);
     digitalWrite(seg_f, LOW); 
     digitalWrite(seg_g, LOW); 
   break;
   case 7: 
     digitalWrite(seg_a, LOW);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, HIGH);
     digitalWrite(seg_e, HIGH);
     digitalWrite(seg_f, HIGH); 
     digitalWrite(seg_g, HIGH); 
   break;
   case 8: 
     digitalWrite(seg_a, LOW);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, LOW);
     digitalWrite(seg_e, LOW);
     digitalWrite(seg_f, LOW); 
     digitalWrite(seg_g, LOW); 
   break;
   case 9: 
     digitalWrite(seg_a, LOW);  
     digitalWrite(seg_b, LOW); 
     digitalWrite(seg_c, LOW); 
     digitalWrite(seg_d, HIGH);
     digitalWrite(seg_e, HIGH);
     digitalWrite(seg_f, LOW); 
     digitalWrite(seg_g, LOW); 
   break;      
   }
   return a;
}

Schematics

Schematic
Jogo palavra t7fe3lnjge

Comments

Similar projects you might like

Digital & Binary Clock In 8 Digits x 7 Segments LED Display

Project showcase by LAGSILVA

  • 1,827 views
  • 2 comments
  • 9 respects

Snap Circuits® - Count Down Launcher

Project tutorial by Daniel Porrey

  • 1,994 views
  • 2 comments
  • 10 respects

Launch Pad Count Down Sequence Display

Project in progress by Douglas Frey

  • 1,535 views
  • 1 comment
  • 13 respects

Arduino + Visual Studio = Fast Dev.

by Ahmed Hamdy

  • 40,443 views
  • 12 comments
  • 105 respects

Temperature Monitoring With DHT22 & Arduino

by Muhammad Afzal

  • 113,865 views
  • 46 comments
  • 81 respects
Add projectSign up / Login