I have a dipswitch of 4 steps to get a binary number that will turn out to decimal from 0 to 15, So I need to get that number and make it the ammount of minutes to make something and also be aware of some input while the time runs out.

So I was thinking of having a variable being equal to millis() and then dividing it by 60,000 which is a minute in millis and If I get an integer that must mean a minute has passed, the problem is that I don't know how to check if the result is an integer or a float.

any advice?


Your method is completely wrong.

You need a variable that contains the value of millis() at the start of your period, whenever that may be (when the switches change? when a button is pressed? since the Arduino was powered up?) and compare that value to the current value of millis(). When the difference between them is greater than or equal to 60000 * 15 then 15 minutes have passed.

Look at BlinkWithoutDelay in the Examples menu in the IDE - it showcases the technique for you.

  • well, the input from the dipSwitch is received in the void setup, as soon as you turn on the arduino. I've tried to use the blink without delay but I'm not sure how to count the minutes, i've even tried changing the interval to the input of the dipSwitch but it's only driving me crazier – baal Nov 9 '15 at 21:12

To my understanding you want to make some sort of device that will count X min. To get X you configure the 4 dip switches to get the time (0000 - 1111 or 0 - 15). The easiest way is to configure 4 pins to INPUT_PULLUP then you wire your switch to those pins and to ground. If the pin is grounded (switch in the on state) it will register a 0 and if the pin is NOT grounded (switch in the off state) it will register a 1.

note: if all switch are "off" you will get a max value of 15 based on my example.

long startTime;
void setup(){
    pinMode(7, INPUT_PULLUP); //8bit
    pinMode(6, INPUT_PULLUP); //4bit
    pinMode(5, INPUT_PULLUP); //2bit
    pinMode(4, INPUT_PULLUP); //1bit

    startTime = millis();

void loop(){
    long inputTime = 0;

        inputTime += 8;

        inputTime += 4;

        inputTime += 2;

        inputTime += 1;

    inputTime = 60000*inputTime;

    if(millis() - startTime <= inputTime){
        //X min has passed -- Do something here if you like

        startTime = millis(); //reset the timer
        //Time not yet reached -- Do something here if you like

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.