set zero to millis

Hi :slight_smile: :slight_smile: :slight_smile: :slight_smile:
i have this and i want to set zero millis who i can do that???

#include <SPI.h>
#include <LiquidCrystal.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;

#define PIR_MOTION_SENSOR 3
bool canchange= false;
int inputPin = 4;              
int pirState = LOW;            
int val = 0;                  
unsigned long time;
unsigned long allagikommatiou;


LiquidCrystal lcd(14, 15, 16, 17, 18, 19);//12, 11, 5, 4, 3, 2
//int8_t current_track = 1;

int tracknum=1;
int kinisi = 0;
long interval = 5000;
unsigned long currentMillis = 0;     // time variable to track running time: current time
unsigned long startingMillis = 0;    // time variable to track running time: starting time
byte result;

void setup() {
pinMode(inputPin, INPUT);    //vazoume ton sencora ws input
Serial.begin(9600);


//ena minima gia tin lcd molis anoigei.....
if(!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!sd.chdir("/")) sd.errorHalt("sd.chdir");
MP3player.begin();
MP3player.setVolume(10,10);

lcd.begin(16, 2);
lcd.print("eimai to junkbox");
}



void loop() {


allagikommatiou = millis();

if(allagikommatiou == 2000){
 Serial.println("5");
 Serial.println(allagikommatiou);
 allagikommatiou = 0 ;
 
}
 //prints time since program startedn
//Serial.println(time);


if(time >= 20000){
 lcd.setCursor(0, 0);
 Serial.println("Petaxe ena skoupidi");
 lcd.setCursor(0, 1);
 Serial.print("gia na paixw");
 MP3player.stopTrack();
 kinisi = 0;
}


 



 

   // set the LED with the ledState of the variable:
   digitalWrite(inputPin, pirState);


 



if(tracknum == 10){
 Serial.println("xana apo thn arxh");
 tracknum = 0;
}

 val = digitalRead(inputPin);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
   if (pirState == LOW) {
     
     kinisi++;
     Serial.print("Sensor 1: ");
     Serial.print(kinisi);
     Serial.println();
     

     if(kinisi == 1){
       MP3player.playTrack(tracknum);
     }
     
     if(kinisi >= 1 && allagikommatiou >= 2000){
      canchange = true;
      Serial.println("mporei na allaxei kommati");
      Serial.println(tracknum);
      allagikommatiou = 0;
      }

     if(canchange == true){
      MP3player.stopTrack();
      tracknum++;
      MP3player.playTrack(tracknum);
      canchange = false;
     }
     
     time=0;
     pirState = HIGH;        
   }
 
 }
 
 else {
 
   if (pirState == HIGH){
   
     pirState = LOW;
   }
 }
}

:o :o

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason just make for more scrolling when we’re trying to read your code.

When your code requires a library that’s not included with the Arduino IDE please always post a link(using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

jimis093:
i have this and i want to set zero millis who i can do that???

What does that even mean? Why would you want to do that?

“i want to set zero millis who i can do that???”

You shouldn’t need to do that.
Capturing two times with millis() or micros() and subtracting, laterTime - earlierTime, will tell you the elapsed time between them, even over a rollover, 0xFFFFFFF0 to 0x000000010 for example, 49.7 days for millis(), 71+ hours for micros().

<ok … i want to set 0 to millis because i want to reset the sensor …>

if(time >= 20000){
lcd.setCursor(0, 0);
Serial.println(“Petaxe ena skoupidi”);
lcd.setCursor(0, 1);
Serial.print(“gia na paixw”);
MP3player.stopTrack();
kinisi = 0;

and i want to reset the sensor for ‘‘MP3player.startTrack’’

I don't see MP3player.startTrack anywhere in your code.

You need to get this concept, it's very important. You should study File > Examples > 02.Digital > BlinkWithoutDelay and the associated tutorial page:

Until you understand every line of that sketch. Do you notice that the LED can keep blinking without ever setting millis() back to zero?