For a school project I'm making a arcade game. I've never worked with arduino before so I barely know how to work with the program.
I'm trying to make a program where the scoreboard counts up everytime a point gets scored.
When the max score is reached, I want to reset the scoreboard to 0 so the game is ready to play again. I've been able to program the count up function but I don't know how to reset the program when the max score have been reached.
As you can see I've been trying to reset by bringing the counter value back to 0 but this doesn't work at all. I know my program isn't the best you've seen, but I hope someone can help me out with this.
could you post the entire program as text, not an image. after pasting, select the code and select the "</>" icon so that it's listed as code without UTF characters
You need to reset the counters... not just the accumulated totals YAZ.
Yes, there are better ways to do what you want, but you’re learning - that’s good !
This is my program so far by following your sugestions but I'm not there yet.
The score that has to be reached is 2000. As you can see there are 3 different points to score (100,250,500). When I'm at 1750 points, and I score +500 points, the score would be 2250 but the max is set on 2000. If my program worked as it should, the count value should be brought back to 0 and the game should be ready to play again.
What happens right now is when I reach for example 2250 points, the lcd shows me 0250. If i continue to play, the score counts up with an extra digit. So instead of +500, the counter goes up with 5000 points. I've been looking for solutions for hours but it's not that simple because I don't really know where the problem is.
(I hope my information about the problem is clear enough)
#include <LiquidCrystal.h>
int button1=8;
int button2=13;
int button3=9;
int val1;
int val2;
int val3;
int count;
int press;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
pinMode(button1,INPUT);
pinMode(button2,INPUT);
pinMode(button2,INPUT);
}
void loop() {
val1=digitalRead(button1);
val2=digitalRead(button2);
val3=digitalRead(button3);
delay(200);
switch(count >= 2000){
default:
if(val1==HIGH)
{
press=count;
count = count +250;
}
if(val2==HIGH)
{
press=count;
count= count +500;
}
if(val3==HIGH)
{
press=count;
count= count +100;
}
break;
case 1:
{count= 0;
break;
}
}
lcd.setCursor(0, 0);
lcd.print("Button Count");
lcd.setCursor(0,1);
lcd.print(count);
}
Hi, @Arthon
I can see you are just over printing your count on the LCD.
This means if you print a four digit number then a three digit number, the fourth digit will not change.
What you do is before you update the number, print blanks in its place, like below.
Thank you! I didn't knew the solution would be so "easy' but my program finaly works
I have no errors so I think the switch...case works, else it's just pure luck the program still works as I hoped it would.