kk logo

99 SEKUNDEN Timer für einen heißen Draht. Die Verdrahtung eurer sieben Segment Anzeige entnehmt ihr bitte aus dem Datenblatt und gleicht mit (void set1(byte value)) für die erste und (void set10(byte value) für die zweite stelle ab. 

 heiser draht mit countdown anzeige bauen 

Arduino Code:

------------------------------------------------------------------------------------

const byte startStopPin = 0, mistakePin = 1, buzzerPin = 16;

long startMillis;

void setup()
{
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);

pinMode(startStopPin, INPUT);
pinMode(mistakePin, INPUT);
pinMode(buzzerPin, OUTPUT);

displayNumber(0);
while(digitalRead(startStopPin) == LOW) // wait for the start signal
{ ; }

startMillis = millis();
}

void loop()
{
long number = 99 - (millis() - startMillis) / 1000;

if (number <= 0)
{
gameOver();
}

if (digitalRead(startStopPin) == HIGH && (millis() - startMillis) > 2000)
{
while(true)
{ ; }
}

if (digitalRead(mistakePin) == HIGH && (millis() - startMillis) > 2000)
{
gameOver();
}


displayNumber(number);
}

void displayNumber(byte x)
{
x %= 100;
set1(~dec27(x % 10));
set10(~dec27(x / 10));
}

void set1(byte value)
{
digitalWrite(2, bitRead(value, 0)); // segment a
digitalWrite(3, bitRead(value, 1)); // segment b
digitalWrite(4, bitRead(value, 2)); // segment c
digitalWrite(5, bitRead(value, 3)); // segment d
digitalWrite(6, bitRead(value, 4)); // segment e
digitalWrite(7, bitRead(value, 5)); // segment f
digitalWrite(8, bitRead(value, 6)); // segment g
}

void set10(byte value)
{
digitalWrite(9, bitRead(value, 0)); // segment a
digitalWrite(10, bitRead(value, 1)); // segment b
digitalWrite(11, bitRead(value, 2)); // segment c
digitalWrite(12, bitRead(value, 3)); // segment d
digitalWrite(13, bitRead(value, 4)); // segment e
digitalWrite(14, bitRead(value, 5)); // segment f
digitalWrite(15, bitRead(value, 6)); // segment g
}

byte dec27(byte decimal) {
if (decimal == 0)
return B00111111;
if (decimal == 1)
return B00000110;
if (decimal == 2)
return B01011011;
if (decimal == 3)
return B01001111;
if (decimal == 4)
return B01100110;
if (decimal == 5)
return B01101101;
if (decimal == 6)
return B01111101;
if (decimal == 7)
return B0000111;
if (decimal == 8)
return B01111111;
if (decimal == 9)
return B01101111;

return 0;
}

void gameOver()
{
displayNumber(0);
digitalWrite(buzzerPin, HIGH);
delay(3000);
digitalWrite(buzzerPin, LOW);
while (true)
{ ; }
}

King of my heart

Let the King of my heart
Be the mountain where I run
The fountain I drink from
Oh, He is my song

Ronnie

schwäbischer tüftler und bastler, kraftsportler, ADHS power, 43 Jahre, 1 Frau, 5 Kinder und 1003 Ideen. 

ronnie berzins at mee