Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
Da li si taster spojio na GND? Da li taster koji koristis NO (normalno otvoren) ili NC (normalno zatvoren)?
Trebat ce tu i debounce da se odradi...
Posts: 1.517
Threads: 19
Joined: Apr 2013
Reputation:
211
Taster je NO, sa GND ide otpornik direktno na pin D13 i kada se taster aktivira dovodi 5V na pin D13 i tako radi, normalno vezanje tastera na Arduino.
Posts: 1.157
Threads: 27
Joined: Oct 2014
Reputation:
313
Pošto je taster ovako vezan onda tvoj uslov za njega treba da glasi:
if (taster == 1 ){ // Svaki put kad se pritisne taster menja se status START ili PAUSA
toggleKey = !toggleKey;
Stavi negde poslednju verziju koda. Ovako je dosta teško za praćenje dokle smo stigli.
Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
10-12-2016, 10:18 AM
(This post was last modified: 10-12-2016, 10:24 AM by me[R]a.)
Ako si tako povezao taster onda to menja stvar jer to je varijanta sa pull down otporom
Sad na neki nacin tvoj pull-down otpor i inetrni pul-up otpori prave naponski razdelnik na tom pinu i doveo si ga u stanje da se nezna ni kad je logicko 1 niti kad je logicko 0
treba da izbacis ovo :
Code: pinMode(keyStart, HIGH) ; // ovom komandom palis interne pullup otpornike..
Kad su ukljuceni pull-up interni otpornici onda ti je pin na arduinu stalno na logickoj jedinici...
Posts: 1.517
Threads: 19
Joined: Apr 2013
Reputation:
211
Code: 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; //
// D
int dig1;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int DTime = 4;
int tmp = 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);
Serial.begin(9600);
}
void loop()
{
digitalWrite( GND1, LOW);
digitalWrite( GND2, LOW);
digitalWrite( GND3, LOW);
digitalWrite( GND4, LOW);
int taster = digitalRead(keyStart);
if(taster == 1 ) // Svaki put kad se pritisne taster menja se status START ili PAUSA
{
toggleKey = !toggleKey;
{
if(toggleKey) //u zavisnosti ako je true(START) onda broj se uvecava i prikazuje novi
{
if(++num > 9999) //ako je false(PAUSE) onda se broj ne uvecava i prikazuje se stalno zadnji
{
num = 0;
}
Serial.println(num); //broj tj pauzirano je brojanje...
}
}
dig1 = num / 1000;
tmp = num - (dig1 * 1000);
dig2 = tmp / 100;
tmp = tmp - (dig2 * 100);
dig3 = tmp / 10;
dig4 = tmp - (dig3 *10);
}
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();
}
@YuMERA
Da li upisao ili obrisao funkciju za uključivanje pullup otpornika, ništa se ne mjenja, isto se ponaša.?
Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
10-12-2016, 03:10 PM
(This post was last modified: 10-12-2016, 03:12 PM by me[R]a.)
Veceras ako stignem sklopicu jedan display sa 4 cifre na pobnoj plocici cisto da proverimo softver...
Daj pun kod koji imas sad da mogu da testiram sa postojecom situacijom...
Posts: 1.517
Threads: 19
Joined: Apr 2013
Reputation:
211
Evo ga:
Code: 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; //
// D
int dig1;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int DTime = 4;
int tmp = 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);
Serial.begin(9600);
}
void loop()
{
digitalWrite( GND1, LOW);
digitalWrite( GND2, LOW);
digitalWrite( GND3, LOW);
digitalWrite( GND4, LOW);
int taster = digitalRead(keyStart);
if(taster == 1 ) // Svaki put kad se pritisne taster menja se status START ili PAUSA
{
toggleKey = !toggleKey;
{
if(toggleKey) //u zavisnosti ako je true(START) onda broj se uvecava i prikazuje novi
{
if(++num > 9999) //ako je false(PAUSE) onda se broj ne uvecava i prikazuje se stalno zadnji
{
num = 0;
}
Serial.println(num); //broj tj pauzirano je brojanje...
}
}
dig1 = num / 1000;
tmp = num - (dig1 * 1000);
dig2 = tmp / 100;
tmp = tmp - (dig2 * 100);
dig3 = tmp / 10;
dig4 = tmp - (dig3 *10);
}
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);
}
.
Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
U prepiski je napravljeno nekoliko sintaksnih gresaka sa viticastim zagradama...
Probaj sad ovaj kod dole pa javi....
Taster moras nekad kratko a nekad duze da drzis da bi promenio Start/Pause to bi se sa softverskim debounce resilo...
Code: 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; //
// D
int dig1 = 0;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int DTime = 4;
int tmp = 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);
Serial.begin(9600);
}
void loop()
{
digitalWrite( GND1, LOW);
digitalWrite( GND2, LOW);
digitalWrite( GND3, LOW);
digitalWrite( GND4, LOW);
int taster = digitalRead(keyStart);
if(taster == 1 ) // Svaki put kad se pritisne taster menja se status START ili PAUSA
{
toggleKey = !toggleKey;
//Serial.println(toggleKey);
} // ************************************** ova nije bila ovde
//{ ************************************** ova je bila viska
if(toggleKey) //u zavisnosti ako je true(START) onda broj se uvecava i prikazuje novi
{
if(++num > 9999) //ako je false(PAUSE) onda se broj ne uvecava i prikazuje se stalno zadnji
{
num = 0;
}
//Serial.println(num); //broj tj pauzirano je brojanje...
}
//} ************************************ ova je bila viska
dig1 = num / 1000;
tmp = num - (dig1 * 1000);
dig2 = tmp / 100;
tmp = tmp - (dig2 * 100);
dig3 = tmp / 10;
dig4 = tmp - (dig3 *10);
//} ************************************ ova je bila viska
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);
}
Posts: 1.517
Threads: 19
Joined: Apr 2013
Reputation:
211
Sad radi kako treba, dobunce ću ja probati sam odrati ako budem znao.
Sad su ostale još par stvari:
1. trebam dodati još jednu cifru da ih bude ukupno 5,
2. sekunde ograničiti na 60 i onda ide jedan minut, da ne ide do 99,
3. i samo još fino podesiti brzinu brojanja, sada prebrzo broji.
Ljudi hvala Vam puno što ste mi pomogli do sada, i što ste izdržali samnom i izborili se mojim željama i prohtjevima.
Posts: 8.738
Threads: 138
Joined: Apr 2013
Reputation:
3.629
10-12-2016, 09:16 PM
(This post was last modified: 10-12-2016, 10:17 PM by mikikg.)
Ovde sam pisao nesto oko debounce, pogledajte:
http://forum.yu3ma.net/showthread.php?tid=690&pid=30809&highlight=Debounce#pid30809
Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
Jedva nabode i za ove 4 cifre gden sad nadje i tu 5.
[attachment=21280]
[attachment=21281]
Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
10-12-2016, 10:01 PM
(This post was last modified: 10-13-2016, 12:36 AM by me[R]a.)
Evo kod sa debounce do duse malo prepravljen u odnosu na orginal jer se moralo prilagoditi tvom kodu
Hvala @mikikg ovo je stvarno jednostavno a radi posao...
Code: /******************************************************************************
debounce.c
written by Kenneth A. Kuhn
version 1.00
This is an algorithm that debounces or removes random or spurious
transistions of a digital signal read as an input by a computer. This is
particularly applicable when the input is from a mechanical contact. An
integrator is used to perform a time hysterisis so that the signal must
persistantly be in a logical state (0 or 1) in order for the output to change
to that state. Random transitions of the input will not affect the output
except in the rare case where statistical clustering is longer than the
specified integration time.
The following example illustrates how this algorithm works. The sequence
labeled, real signal, represents the real intended signal with no noise. The
sequence labeled, corrupted, has significant random transitions added to the
real signal. The sequence labled, integrator, represents the algorithm
integrator which is constrained to be between 0 and 3. The sequence labeled,
output, only makes a transition when the integrator reaches either 0 or 3.
Note that the output signal lags the input signal by the integration time but
is free of spurious transitions.
real signal 0000111111110000000111111100000000011111111110000000000111111100000
corrupted 0100111011011001000011011010001001011100101111000100010111011100010
integrator 0100123233233212100012123232101001012321212333210100010123233321010
output 0000001111111111100000001111100000000111111111110000000001111111000
I have been using this algorithm for years and I show it here as a code
fragment in C. The algorithm has been around for many years but does not seem
to be widely known. Once in a rare while it is published in a tech note. It
is notable that the algorithm uses integration as opposed to edge logic
(differentiation). It is the integration that makes this algorithm so robust
in the presence of noise.
******************************************************************************/
/* The following parameters tune the algorithm to fit the particular
application. The example numbers are for a case where a computer samples a
mechanical contact 10 times a second and a half-second integration time is
used to remove bounce. Note: DEBOUNCE_TIME is in seconds and SAMPLE_FREQUENCY
is in Hertz */
#define DEBOUNCE_TIME 0.3
#define SAMPLE_FREQUENCY 10
#define MAXIMUM (DEBOUNCE_TIME * SAMPLE_FREQUENCY)
/* These are the variables used */
//unsigned int input; /* 0 or 1 depending on the input signal */
unsigned int integrator; /* Will range from 0 to the specified MAXIMUM */
//unsigned int output; /* Cleaned-up version of the input signal */
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; //
// D
int dig1 = 0;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int DTime = 4;
int tmp = 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);
}
void loop()
{
digitalWrite( GND1, LOW);
digitalWrite( GND2, LOW);
digitalWrite( GND3, LOW);
digitalWrite( GND4, 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
{
if(++num > 9999)
{
num = 0;
}
}
dig1 = num / 1000;
tmp = num - (dig1 * 1000);
dig2 = tmp / 100;
tmp = tmp - (dig2 * 100);
dig3 = tmp / 10;
dig4 = tmp - (dig3 *10);
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);
}
Posts: 1.517
Threads: 19
Joined: Apr 2013
Reputation:
211
Probao i ovu zadnju verziju sa debounce, savršeno radi, ma extra.
Sad još one 3 stavke što sam gore napisao da nekako ''skarabudžimo''.?
Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
(10-12-2016, 09:05 PM)Makso Wrote: Sad su ostale još par stvari:
1. trebam dodati još jednu cifru da ih bude ukupno 5,
2. sekunde ograničiti na 60 i onda ide jedan minut, da ne ide do 99,
3. i samo još fino podesiti brzinu brojanja, sada prebrzo broji.
Nije bas jasno da brojis sekunde. Mislis zadnje dve cifre 4. i 5. da broje sekunde od 00-59 pa da onda 2. i 3. za svaki 60 sec uvecaju se za 00-59 minuta i kad dosegnes tih 59 minuta da samo 1. cifra prikaze sat od 0-9 ?
Ako sam dobro shvatio.
Tacno brojanje sekundi mora ici preko interrupt-a
Posts: 1.517
Threads: 19
Joined: Apr 2013
Reputation:
211
10-12-2016, 10:37 PM
(This post was last modified: 10-12-2016, 10:38 PM by Makso.)
Brojevi bi trebali izgledati ovako:
99 : 60 : 9 (tu sam napisao brojeve do koliko broji da bude jasnije),
mm : ss : s - znači prve dvije cifre broje minute i one idu do kraja tj. 99 minuta, druge dvije cifre su sekunde (one idu do 60 kao u realnom vremenu i onda dodaje se jedan minut i tako u krug svakih 60 sekundi) a peta cifra treba da bude stotinka i ona broji do 9 i dodaje jedan sekund i sve tako), nadam se da me sad razumiješ, ne trebaju mi sati.
Prve dvije (1 i 2) cifre su minute, druge dvije (3 i 4) cifre su sekunde i peta (5) cifra su stotinke.
Posts: 111
Threads: 6
Joined: Sep 2016
Reputation:
35
Ne baratam Arduinom, ali ovo precizno merenje vremena generalno nema veze sa mikrokontrolerom. Ako se postavi neka vremenska baza i namesti da se po njenom isteku oglasi interapt, onda postoji kašnjenje u vidu nekoliko mikrosekundi da procesor hardverski obavi interapt. To se kašnjenje gomila iz sekunde u sekundu. Možda nije bitno za ovu aplikaciju, ali generalno je bitno. Sad ne znam možda ima neki trik da nema kašnjenja ili ja nisam dobro shvatio kako se broje sekunde pomoću interapta.
Posts: 1.157
Threads: 27
Joined: Oct 2014
Reputation:
313
Ne gomila se kašnjenje već je uvek isto. Pod uslovom da znaš koliko je uvek ga možeš obraditi softverom.
Posts: 665
Threads: 40
Joined: Jul 2015
Reputation:
398
Naravno da nisam mislio na tacno merenje vremena. Ideja je da napravim timer interrupt na svakih 100ms i da samo brojac uvelicavam za +1 u svakom izazvanom prekidu. Hardversko kasnjenje izvrsavanja interrupt-a i vreme za izvrsavanje programske instrukcije unutar interrupt-a jesu vremenska kasnjenja ali za ovaj primer gde je maksimalni interval od 0 -100 min mislm da nece imati znacajnog uticaja...
Posts: 111
Threads: 6
Joined: Sep 2016
Reputation:
35
U pravu si. Prevideo sam da i za to vreme interapta (nekoliko ciklusa ili već kako je proizvođač deklarisao), clock 'obrće' brojač, pa ako je došao do kraja broji od početka. Faktički i nije bitno to konstantno kašnjenje, jer je u biti malo. Radio sam sa kristalom za sat, a nisam u trenutku skontao da je princip isti, stim što ovde 'obrće' brojač kristal za procesor (koji uvek radi). Hvala na ispravci!
Posts: 111
Threads: 6
Joined: Sep 2016
Reputation:
35
Nešto me buni u vezi generisanje sekunde, pa ako može pojašnjenje, nadam se da nije off topic. Ja sam sekundu generisao kristalom za sat i 16 bitnim brojačem, a pošto su oni 'upareni' sve je išlo olako. Internet je pun raznoraznih kodova koje svako piše, pa bih ovde pitao za ideju. Pošto često imamo na raspolaganju jedan brojač (neka bude 8 bitni) i kristal koji opet možda moramo da izaberemo na osnovu bitnijih uslova, ispada da u brojač moramo da ubacujemo ofset. Ja generisanje osnove za sekundu gledam na sledeći način (deskriptivni algoritam):
interapt (brojač prešao iz FF u 00) ;
;procesor obrađuje interapt, a imamo nepoznato vreme obrade, a pošto klok radi brojač broji
zaustavimo brojač
ubacimo vreme u predodređen ofset; ako nam je trajao 3 kloka, onda ćemo ubaciti broj 3, ako je 5 onda 5.
spreman za novi interapt.
Sve ove radnje imaju poznato vreme, a brojač je izbrojio to nepoznato vreme za interapt.
Ako ne bismo brojali to nepoznato vreme, onda bi unosilo grešku. Da li je ovo ispravno, ako ne kako se radi generisanje osnove za sekundu (ne treba mi kod, samo deskriptivno).
|