Evo @Makso pa probaj ja sam kontrolisao 20-tak minuta brojanje i bilo je ok...
Jedino sto ne vidim kako se vrti ova 5 cifra jer mrzilo me da dodajem na ovu moju test skalameriju petu cifru..
"GND" Pin za tu petucifru stavio sam na A3 pin arduina
Nisam stigo ranije da uradim kod, zadrzala me jedna Dunja od 19 gradi..
Pa ako se i podkrade kakva greska ne zameri...
Jedino sto ne vidim kako se vrti ova 5 cifra jer mrzilo me da dodajem na ovu moju test skalameriju petu cifru..
"GND" Pin za tu petucifru stavio sam na A3 pin arduina
Code:
#define DEBOUNCE_TIME 0.3
#define SAMPLE_FREQUENCY 10
#define MAXIMUM (DEBOUNCE_TIME * SAMPLE_FREQUENCY)
unsigned int integrator; //Will range from 0 to the specified MAXIMUM
int keyStart = 13; //deklarises i inicijalizujes globalnu promenljivu za taster
boolean toggleKey = false; //promenljiva za status tastera dali ako je stisnut menja vrednost START/PAUSA
int num = 0; //tvoja promenljiva za broj samo sto je sad inicijalizujemo
int aPin = 2; // A
int bPin = 3; // ________
int cPin = 4; // | |
int dPin = 5; // F | | B
int ePin = 6; // | G |
int fPin = 7; // |________|
int gPin = 8; // | |
int GND1 = 9; // | |
int GND2 = 10; // E | | C
int GND3 = 11; // |________|
int GND4 = 12; //
int GND5 = A3; // D
int dig1 = 0;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int dig5 = 0;
int DTime = 6;
int tmp = 0;
int sekunda=0;
int minuta=0;
void setup()
{
pinMode(keyStart, INPUT); // ovo stavis u void setup()
pinMode(aPin, OUTPUT);
pinMode(bPin, OUTPUT);
pinMode(cPin, OUTPUT);
pinMode(dPin, OUTPUT);
pinMode(ePin, OUTPUT);
pinMode(fPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(GND1, OUTPUT);
pinMode(GND2, OUTPUT);
pinMode(GND3, OUTPUT);
pinMode(GND4, OUTPUT);
pinMode(GND5, OUTPUT);
//set timer1 interrupt at 10Hz
cli(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; //initialize counter value to 0
// set compare match register for 10hz increments
OCR1A = 1562; // = (16*10^6) / (10*1024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
}
ISR(TIMER1_COMPA_vect){ //timer1 interrupt 10Hz
if (++num>9){
if (++sekunda>59){
if (++minuta>99){
minuta=0;
}
sekunda=0;
}
num=0;
}
dig5 = num;
dig4 = sekunda % 10;
dig3 = (sekunda/10);
dig2 = minuta % 10;
dig1 = (minuta/10);
}
void loop()
{
digitalWrite( GND1, LOW);
digitalWrite( GND2, LOW);
digitalWrite( GND3, LOW);
digitalWrite( GND4, LOW);
digitalWrite( GND5, LOW);
int taster = digitalRead(keyStart);
if(taster == 1 ){ // Svaki put kad se pritisne taster menja se status START ili PAUSA
if (integrator > 0){
integrator--;
toggleKey = !toggleKey;
}
}
else if (integrator < MAXIMUM){
integrator++;
}
if(toggleKey){ //u zavisnosti ako je true(START) onda broj se uvecava i prikazuje novi
interrupts(); // enable all interrupts
}
else {
noInterrupts(); // disable all interrupts
TCNT1 = 0;//initialize counter value to 0
}
digitalWrite( GND5, HIGH); //digit 5
pickNumber(dig5);
delay(DTime);
digitalWrite( GND5, LOW);
clearLEDs();
digitalWrite( GND4, HIGH); //digit 4
pickNumber(dig4);
delay(DTime);
digitalWrite( GND4, LOW);
clearLEDs();
digitalWrite( GND3, HIGH); //digit 3
pickNumber(dig3);
delay(DTime);
digitalWrite( GND3, LOW);
clearLEDs();
digitalWrite( GND2, HIGH); //digit 2
pickNumber(dig2);
delay(DTime);
digitalWrite( GND2, LOW);
clearLEDs();
digitalWrite( GND1, HIGH); //digit 1
pickNumber(dig1);
delay(DTime);
digitalWrite( GND1, LOW);
clearLEDs();
}
void pickNumber(int x){
switch(x){
case 0: zero(); break;
case 1: 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;
default: break;
}
}
void clearLEDs()
{
digitalWrite( 2, LOW); // A
digitalWrite( 3, LOW); // B
digitalWrite( 4, LOW); // C
digitalWrite( 5, LOW); // D
digitalWrite( 6, LOW); // E
digitalWrite( 7, LOW); // F
digitalWrite( 8, LOW); // G
}
void one()
{
digitalWrite( aPin, LOW);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, LOW);
digitalWrite( ePin, LOW);
digitalWrite( fPin, LOW);
digitalWrite( gPin, LOW);
}
void two()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, LOW);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, LOW);
digitalWrite( gPin, HIGH);
}
void three()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, LOW);
digitalWrite( fPin, LOW);
digitalWrite( gPin, HIGH);
}
void four()
{
digitalWrite( aPin, LOW);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, LOW);
digitalWrite( ePin, LOW);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
}
void five()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, LOW);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, LOW);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
}
void six()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, LOW);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
}
void seven()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, LOW);
digitalWrite( ePin, LOW);
digitalWrite( fPin, LOW);
digitalWrite( gPin, LOW);
}
void eight()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
}
void nine()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, LOW);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, HIGH);
}
void zero()
{
digitalWrite( aPin, HIGH);
digitalWrite( bPin, HIGH);
digitalWrite( cPin, HIGH);
digitalWrite( dPin, HIGH);
digitalWrite( ePin, HIGH);
digitalWrite( fPin, HIGH);
digitalWrite( gPin, LOW);
}
Nisam stigo ranije da uradim kod, zadrzala me jedna Dunja od 19 gradi..
Pa ako se i podkrade kakva greska ne zameri...