Banner Ausblenden
Kleines Logo

Willkommen auf PSI-Online

Sie befinden sich in: Unterrichtsangebote Fächer Fachbereich III Informatik Arduino Sonstiges Arduino Stoppuhr

Arduino Stoppuhr


Die Stoppuhr wird bei der Alarmanlage als Timer für das ungehinderte durchqueren des alarmgesicherten Durchgangs verwendet.

Material:
- Arduino Mega/Uno
- Steckbrett
- LCD-Zeichen-Display
- 10K Potentiometer
- 2 Taster
- 330 Widerstand
- 2x 10K Widerstand
- Verbindungskabel

Programm:

#include //Verbindung zwischen der 4-stelligen 7-Segement-Anzeige und dem Uno Board
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;
int p = 9;
int d4 = 10;
int d3 = 11;
int d2 = 12;
int d1 = 13;
//mit diesem Befehl wird festgelegt welche Pin mit welcher Pin verbunden ist
long n = 0;                                                                                                     
int x = 100;
int del = 5;
int val = 1111;
int count = 0;
void setup()
{
  pinMode(d1, OUTPUT);
  pinMode(d2, OUTPUT);
  pinMode(d3, OUTPUT);
  pinMode(d4, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(p, OUTPUT);// Legt den Digitalen Pin als Ausgang
  Timer1.initialize(100000); //10000 Mikrosekunden
  Timer1.attachInterrupt( add );                                                                    
}
/***************************************/ 
void loop()
{
  int i,j;
  clearLEDs();
  pickDigit(0);
  pickNumber((n/1000));
  delay(del);//unterbrechung
 
  clearLEDs();
  pickDigit(1);
  pickNumber((n%1000)/100);
  delay(del);
 
  clearLEDs();
  pickDigit(2);
  //dispDec(3);
  pickNumber(n%100/10);
  delay(del);
 
  clearLEDs();
  pickDigit(3);
  pickNumber(n%10);
  delay(del);
}
/**************************************/ 
void pickDigit(int x)                                                                                                           
{
  digitalWrite(d1, HIGH); //setzt die LED auf
  digitalWrite(d2, HIGH);
  digitalWrite(d3, HIGH);
  digitalWrite(d4, HIGH);
 
  switch(x)//anweisung
  {
    case 0:
    digitalWrite(d1, LOW); //setzt die LED aus
    break;//abweichung der Schleife
    case 1: //etwas tun wenn x
    digitalWrite(d2, LOW);
    break;
    case 2:
    digitalWrite(d3, LOW);
    break;
  default:
    digitalWrite(d4, LOW);
    break;
  }
}
 
void pickNumber(int x)
{
  switch(x)//anweisung
  {
    default://standart optional
    zero();
    break;//abweichung der Schleife
    case 1: //etwas tun wenn x
    one();
    break;
    case 2:
    two();
    break;
    case 3:
    three();
    break;
    case 4:
    four();
    break;
  case 5:
    five();
    break;
  case 6:
    six();
    break;
  case 7:
    seven();
    break;
  case 8:
    eight();
    break;
  case 9:
    nine();
    break;
  }
}
 
void dispDec(int x)  //                                                                             
{
  digitalWrite(p, HIGH);//setzt die LED auf
}
 
void clearLEDs()  /                                                                                            
{
  digitalWrite(a, LOW);//setzt die LED aus
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
  digitalWrite(p, LOW);
}
 
void zero()  //
{
  digitalWrite(a, HIGH); //setzt die LED auf
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}
 
void one()  //
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
 
void two()  //
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
}
void three() 
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
}
 
void four()  //
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
 
void five()  //
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
 
void six()  /
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
 
void seven()  //
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
 
void eight()  /
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
 
void nine()  //
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
/*******************************************/
void add()
{
    // Toggle LED
    count ++;
    if(count == 10)
    {
      count = 0;
      n ++;
      if(n == 10000)
      {
        n = 0;
      }
    }
}

 

Erstellt: Eva Zapp (08.11.2016) Letzte Änderung: Jacob Busshart (28.06.2017)