/* Dart Scorer
First 3 digit for home score
4 digit for home leg amount
5 digit for guest leg amount
Last 3 digit for guest score
With keypad I can choice game type: ex.
1 time press A=501
2 time press A=301
3 time press A=180
4 time press A= High Score (start from 0 and input every score for 7 turns (21 darts))
or if possible to add mechanical or digital selector for games)
B=Press and and type your initial score (Press "B" and type ex. 180 for start from 180 to 0)
C= + (sum scores(often happend that a player can't sum rapidly every darts points))
D=Enter score
=Memory down (show previous inputs and add ability to clear them (if someone made a mistake))
#=Darts trown
When I input the score played I need to see it on display (and I can insert max 180)
A buzzer that buzz when I press something, and play little jingle when someone end game
Add possibility to use bluetooth numeric keyboard??? like this https://www.bing.com/images/search?view=detailV2&ccid=3ciocstC&id=E0AA6B26000A4E9645CA5A6878B3CABFE1CFDD25&thid=OIP.3ciocstCr_XkAtdHxpYmnQHaHa&mediaurl=https%3a%2f%2fwww.ceotech.it%2fwp-content%2fuploads%2f2019%2f12%2fsatechi_keypad_number__ceotech_8.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.ddc8a872cb42aff5e402d747c696269d%3frik%3dJd3P4b%252fKs3hoWg%26pid%3dImgRaw%26r%3d0&exph=1500&expw=1500&q=tastierino+numerico+bluetooth&simid=608006162543563874&FORM=IRPRST&ck=202675285E0F2E6B5A0BFAFE48DD3FE1&selectedIndex=43&itb=0&ajaxhist=0&ajaxserp=0
*/
/*
Arduino | coding-help
Help for create a dart scorer with 7 segment digits and esp32
aledre% — 4/12/24 at 9:30 AM
Hi, I'm very new in coding, but I have (someone gift me)
some 7 segment digits... with a lot o googling, I connect
3 digit to esp32 and I can print numbers on.
Now I need help for coding it for use as a dart scorer...
so start from 501 and with keyboard input score sustract to 0
for win a game... can anyone help me?
In a real circuit you must use resistors on the segments,
and a transistor on each digit.
https://speedyhiredarts.com/darts-rules
*/
const int START_VAL = 501;
const int INTERVAL = 1000;
//const int MAX_DIGITS = 3;
const int NUM_CHARS = 8;
const int DATA_PIN = 33;
const int LATCH_PIN = 25;
const int CLOCK_PIN = 26;
//const int DIGIT_PINS[MAX_DIGITS] = {12, 14, 27};
/*
const int SEGMENTS[] = { // segments a b c d e f g dp
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110, // 9
B00000000 // Blank
};
*/
const int SEGMENTS[] = { // segments e g f a b dp c d
B10111011, // 0
B00001010, // 1
B11011001, // 2
B01011011, // 3
B01101010, // 4
B01110011, // 5
B11110011, // 6
B00011010, // 7
B11111011, // 8
B01111011, // 9
B00000000 // Blank
};
boolean newData = false;
char receivedChars[NUM_CHARS]; // an array to store the received data
int scoreVal = START_VAL;
int oldScore = 0;
//unsigned long prevMillis = 0;
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= NUM_CHARS) {
ndx = NUM_CHARS - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
int showNewData() {
int dataNumber = 0;
if (newData == true) {
if (receivedChars[0] == 'r') {
scoreVal = START_VAL;
} else {
dataNumber = atoi(receivedChars);
Serial.print("Points entered: ");
Serial.println(dataNumber);
}
newData = false;
}
return dataNumber;
}
/*
// for hardware test
void testDisplay() {
writeShiftDigit(0, 1);
writeShiftDigit(1, 2);
writeShiftDigit(2, 3);
}
*/
void updateDisplay(int scoreVal) {
// with leading zero blanking
int displayValH = scoreVal < 100 ? 10 : (scoreVal % 1000) / 100; // hundreds
int displayValD = scoreVal < 10 ? 10 : (scoreVal % 100) / 10; // tens
int displayValU = scoreVal % 10; // units
// write values to display
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[8]);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[7]);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[6]);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[5]);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[4]);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[3]);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[2]);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[1]);
digitalWrite(LATCH_PIN, HIGH);
//writeShiftDigit(0, displayValH);
//writeShiftDigit(1, displayValD);
//writeShiftDigit(2, displayValU);
}
/*
void writeShiftDigit(int digit, int number) {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, ~SEGMENTS[number]);
digitalWrite(LATCH_PIN, HIGH);
digitalWrite(DIGIT_PINS[digit], LOW);
digitalWrite(DIGIT_PINS[digit], HIGH);
}
*/
void setup() {
Serial.begin(9600);
pinMode(DATA_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
//for (int i = 0; i < MAX_DIGITS; i++) {
//pinMode(DIGIT_PINS[i], OUTPUT);
//digitalWrite(DIGIT_PINS[i], HIGH);
//}
Serial.println("\nDart Score - ready");
}
void loop() {
delay(10); // speeds up wokwi sim
//testDisplay();
recvWithEndMarker();
int pointVal = showNewData();
scoreVal = scoreVal - pointVal;
if (scoreVal < 0) {
Serial.println("Bust!");
oldScore = scoreVal;
scoreVal = scoreVal + pointVal;
}
if (scoreVal != oldScore) {
oldScore = scoreVal;
Serial.print("Current score: ");
Serial.println(scoreVal);
if (scoreVal == 0) {
Serial.println("WIN!");
Serial.println("Type 'r' to restart.");
}
}
updateDisplay(scoreVal);
}