Hello everyone!
I have a problem in programing a arduino uno rev3 board.
I want to make a 2 digit counter for a basketball hoop using:
-ARDUINO UNO
-2 TPIC6B595N
-2 7-SEGMENT RED 6.5" DISPLAY( common anode, 12v)
-1 MICROSWITCH (2 way, NC/NO datasheet attached).
I'we already made the PCB and soldered everything...made all connections and tried to write a code but with no result, my knowledge in programing is low...
can someone help me with the code ?
This is the principle of operation:
-start from 0
-count 1 every time the switch is touch
-continue for 1 minute
-show the final score
-push reset button to start over.
I attached the circuit scheme.
Thank you for your attention!
so...I wrote a code that counts from 0 to 100 that really works...whoow...that is something...it's one week i'm into arduino world...
i'ts true..i have founded some codes on the web but none of them worked with my configuration...so after a long session of editing and reediting codes i finally got to this:
// Contatore 00-99
#define LATCH 4
#define CLK 3
#define DATA 2
//This is the hex value of each number stored in an array by index num
byte digitOne[10]= {
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
byte digitTwo[10]= {
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
int i;
void setup(){
pinMode(LATCH, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(DATA, OUTPUT);
}
void loop(){
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, MSBFIRST, ~digitTwo[i]); // digitTwo
shiftOut(DATA, CLK, MSBFIRST, ~digitOne[j]); // digitOne
digitalWrite(LATCH, HIGH);
delay(1000);
}
}
}
This work...don't really understand how but it counts...only thing is that the first shift register is actually the second digit and the second register is the first digit...no problem here i simply switch post...
Now i must somehow implement a push button in the code that do the counting process but i get stuck...
i get the counting start by pushing the button but it will keep counting by himself up to 99 and then stops...reseting the board will get all segment(in the 7 segments displays) on and pushing the button will start the counting:
// button count bad1
#define LATCH 4
#define CLK 3
#define DATA 2
const int BUTTON = 10;
int val = 0;
int old_val = 0;
//This is the hex value of each number stored in an array by index num
byte digitOne[10]= {
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
byte digitTwo[10]= {
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
int i;
void setup(){
pinMode(LATCH, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop(){
val = digitalRead(BUTTON);
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, MSBFIRST, ~digitTwo[i]); // digitTwo
shiftOut(DATA, CLK, MSBFIRST, ~digitOne[j]); // digitOne
digitalWrite(LATCH, HIGH);
delay(1000);
}
}
}
}
someone heave any ideas on how to proceed?
Thank's
_2_digit_counter_00-99.ino.ino (882 Bytes)
OK....i finally got the code...or almost...the only thing that's missing is to add a timer....like DO THIS FOR 30 SECONDS/1 MINUTE...if someone has an ideea on how to do this please reply...thank you....
here is the final code working:
// button count GOOD1
#define LATCH 4
#define CLK 3
#define DATA 2
const int buttonPin = 10;
int buttonPushCounter = 0; //counter for the number of button presses
int buttonState = 0; //current state of the button
int lastButtonState = 0; //previous state of the button
//This is the hex value of each number stored in an array by index num
byte digitOne[10]= {
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
byte digitTwo[10]= {
B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
int tens;
int ones;
void setup(){
pinMode(LATCH, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(buttonPin, INPUT); //initialize the button pin as a input
}
void loop(){
buttonState = digitalRead(buttonPin); //read the pushbutton input pin
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
buttonPushCounter++;
tens = buttonPushCounter/10;
ones = buttonPushCounter-tens*10;
{ digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, MSBFIRST, ~digitTwo[ones]); // digitTwo
shiftOut(DATA, CLK, MSBFIRST, ~digitOne[tens]); // digitOne
digitalWrite(LATCH, HIGH);
}
}
lastButtonState = buttonState; // save the current state as the last state, for next time through the loop
}
delay(100);
}
thank you ..BY!