Splitting minutes() - possible?

edited November 2013 in How To...

Hey colleges, i need your question in this point: I want to write a clock in the style of dominoe. I've already programmed the hours, but the minutes are a bit harder to me. The minutes have to be divided into the first and the second number. Here's an example: Minute 42 becomes 4 and 2. Is Processing able to give me these numbers individually?

Check out this image for better understanding of what i want to do. creative-clocks-11-3

Thank's alot for your help! :)

Answers

  • edited November 2013
    int tens = mins / 10;
    int units = mins % 10;
    

    NB integer division

  • edited November 2013

    Thank's alot for your fast answer, that seems to work! :)

    I've another beginners questions regarding the hours. How do i map the hours from 1-24 to 1-12? Whenever i use float hour() = map(hour(),0, 23, 0, 12) i get an error message. Thank's in advance. ;)

  • edited November 2013

    How about if ((hours %= 12) == 0) hours = 12;? (*)

  • Answer ✓

    Whenever i use float hour() = map(hour(),0, 23, 0, 12) i get an error message.

    you can't assign anything to hour(), it's a method. h is fine though.

    also, why would it be a float?

    int h = hour() % 12; // from 0 - 23 to 0 - 11
    if (h == 0) {
      h = 12; // now 1 - 12
    }
    
  • Thank's alot for these fast answers. I'm currently working on the code and everything works fine now.

    Thank you! :)

Sign In or Register to comment.