i make a TIC TAC BOOM BOMB with arduino and i want to show how much time they got left to play.
Somebody that can help me with te code. I'm really struggling.
int motorPin = 3; //motor transistor is connected to pin 3
int Buttonpin = 2; //schakelaar is pin 2
int onoffbutton = 4; //schakelaar is pin 4
int ledje = 5; //ledje is pin 5 VSQA void setup()
Making people who want to help you guess what your code is will be time consuming and would be a big struggle. I suspect if we had to guess your code it would be, also, a struggle.
If the code, that you want help with, was posted in code tags, then the guessing your code part would be completed and we can then move onto troubleshooting your code.
Different displays and different display chips work differently. So, are you able to display numbers correctly without worrying about time?
If you just want to display seconds that should be straightforward. If you want minutes & seconds you'll probably want two different variables for minutes & seconds.
And note that an unsigned integer only counts-up to about 64,000 so for milliseconds you'll usually want an unsigned long. Once you've converted to minutes & seconds, integers are fine.
I now have an timer on my LCD display but if i set in the code that he chose a random time between 0 seconds and 1 minute 30 seconds he chose a random time every second.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
long minute;
long second ;
int indication = 10; //Connect LED or Buzzer to digital pin 10
void setup() {
pinMode(indication, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("MM:SS");
}
void loop() {
minute = random(0,2);
second = random(0,59);
long countdown_time = (minute * 60) + second;
long countdowntime_seconds = countdown_time - (millis() / 1000);
if (countdowntime_seconds >= 0) {
long countdown_minute = ((countdowntime_seconds / 60) % 60);
long countdown_sec = countdowntime_seconds % 60;
lcd.setCursor(4, 1);
if (countdown_minute < 10) {
lcd.print("0");
}
lcd.print(countdown_minute);
lcd.print(":");
if (countdown_sec < 10) {
lcd.print("0");
}
lcd.print(countdown_sec);
if (countdowntime_seconds == 0) {
digitalWrite(indication, HIGH);
}
}
delay(500);
}
I now have this code but it choose every second another time. How can i change the code that he choose one time a random and then he countdown. If i push then another button it choose another random time
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
long minute;
long second ;
int indication = 10; //Connect LED or Buzzer to digital pin 10
void setup() {
pinMode(indication, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("MM:SS");
}
void loop() {
minute = random(0,2);
second = random(0,59);
long countdown_time = (minute * 60) + second;
long countdowntime_seconds = countdown_time - (millis() / 1000);
if (countdowntime_seconds >= 0) {
long countdown_minute = ((countdowntime_seconds / 60) % 60);
long countdown_sec = countdowntime_seconds % 60;
lcd.setCursor(4, 1);
if (countdown_minute < 10) {
lcd.print("0");
}
lcd.print(countdown_minute);
lcd.print(":");
if (countdown_sec < 10) {
lcd.print("0");
}
lcd.print(countdown_sec);
if (countdowntime_seconds == 0) {
digitalWrite(indication, HIGH);
}
}
delay(500);
}
Since hardware is involved it would be best if you posted an accurate schematic of your circuit as you have it wired. Frizzy pictures are not schematics they are wiring diagrams and almost useless. Also post links to the hardware devices that give technical information, links to places like Amazon generally give sales information, not technical information.
Your two topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.