kk logo

Heißer Draht Code mit Stoppuhr (8-Stellige 7-Segmentanzeige mit serieller Ansteuerung (MAX7219), Arduino komp.) und Summer.

heisser draht mit stoppuhr bauanleitung

 

 

// code by:   Hugo T. 

 

#include "LedControl.h"
LedControl lc = LedControl(12, 11, 10,1 );

const int buttonPin = 2;    // Start, Stopp, Reset PIN
const int failurePin = 4;    // Fehler PIN
const int beeepPin = 13;  // Summer Pin (je nach Summer über einen Transitor)

void setup() {
lc.shutdown(0, false);
lc.clearDisplay(0);
lc.setIntensity(0, 15);

// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(failurePin, INPUT);
pinMode(beeepPin, OUTPUT);
}

void printDashes() {

lc.setChar(0, 0, '-', false);
lc.setChar(0, 1, '-', false);
lc.setChar(0, 2, '-', false);
lc.setChar(0, 3, '-', false);
lc.setChar(0, 4, '-', false);
lc.setChar(0, 5, '-', false);
lc.setChar(0, 6, '-', false);
lc.setChar(0, 7, '-', false);

}
void blink(int times)
{


for (int i = 0; i < times; i++) {

lc.setScanLimit(0, 7);
lc.clearDisplay(0);

printDashes();

delay(150);
lc.clearDisplay(0);

lc.setScanLimit(0, 0);
delay(150);
}


}

void countdown(int counter)
{

while (counter >= 0)
{

int maxDigit = 0;

int n = counter;
for (int i = 0; i < 8; i++) {
int digit = n % 10;
n = n / 10;

lc.setDigit(0, i, digit, false);
if (digit)
{
maxDigit = i;
}
}

lc.setScanLimit(0, maxDigit);

delay(500);
lc.clearDisplay(0);
delay(100);

counter--;
}

}

void displayNumbers(int counter, int seconds, int minutes)
{
int maxDigit = 0;

showTime(counter, 0);
showTime(seconds, 3);
showTime(minutes, 6);

lc.setChar(0, 2, '-', false);
lc.setChar(0, 5, '-', false);


}

void showTime(int value, int positionStart) {
int maxDigit = 0;
int n = value;
int positionEnd = positionStart+2;
for (int i = positionStart; i < positionEnd; i++) {
int digit = n % 10;
n = n / 10;

lc.setDigit(0, i, digit, false);
if (digit)
{
maxDigit = i;
}
}

}

int counter = 0;
int seconds = 0;
int minutes = 0;
int didStart = 0;
int startButtonState = 0;
int failureButtonState = 0;

void loop() {
if (counter > 100) {
counter = 0;
seconds++;
}

if (seconds > 60) {
seconds = 0;
minutes++;
}

displayNumbers(counter, seconds, minutes);
startButtonState = digitalRead(buttonPin);
failureButtonState = digitalRead(failurePin);

if (didStart == 1 | startButtonState == 1)
{
if (didStart == 0) {
digitalWrite(beeepPin, HIGH);
}

if (seconds > 1) {
digitalWrite(beeepPin, LOW);
}

didStart = 1;

if (seconds > 1 & startButtonState == 1)
{
digitalWrite(beeepPin, HIGH);
delay(1500);
digitalWrite(beeepPin, LOW);
do
{
startButtonState = digitalRead(buttonPin);
} while (startButtonState == 0 );
counter = 0;
seconds = 0;
minutes = 0;
displayNumbers(counter, seconds, minutes);
didStart = 0;
delay(200);
}

if(failureButtonState == 1){
counter = 0;
seconds = 0;
minutes = 0;
displayNumbers(counter, seconds, minutes);
didStart = 0;
digitalWrite(beeepPin, HIGH);
delay(3000);
digitalWrite(beeepPin, LOW);
}

if (didStart != 0) {
delay(10);
lc.clearDisplay(0);
counter++;
}
}

//lc.clearDisplay(0);
}

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