Simple Math Question

sodeaf

Senior Member
Hey Guys.. Just working on my 4 x 7 segment display using a 28x2

I will be using the 4 digits for both "Countdown Pulse Display" or could be used as a "4 Digit 15 Min Count down clock"
For instance... ride a bike for 500 wheel revolutions, or ride a bike for 15 minutes..

I was wondering why I cant get this to work in a single string of code..


Timer = 0
Time = 900

b10 = time-timer/60 (min)
b11 = time-timer//60 (sec)

w9 = b10*100 + b11 'Using this number to display on the 4 segments.. dig 0 dig 1 dig 2 dig 3

The above works fine.. But I have been trying for hours wondering why I cant get this on a single line of code, and not have to use b10 and b11
________________________________________________________________

For instance

w9 = time-timer/60*100 + time-timer//60 (Why does this not work.. will only show seconds.. in simulator.. I have tried everything, put brackets around them.. still wont work.. )
(minutes) + (Seconds)
This way I can set my "display code" to read each digit of w9 for the clock and or pulse counter... depending on the mode I have set it too..

Can someone please explain this to me.. I am a newbie.. I just need to know why it don't work, and if there is a solution.. I cant seem to find the answer anywhere..

Thanks Steve
 

westaust55

Moderator
The PICAXE math performs the operations strictly left to right on each program line with no precedence. Brackets are not yet accepted for any chips (see the PE revision notes).
Therefore your calculation when given as:
w9 = time-timer/60*100 + time-timer//60​

is the same as
w9 = ((time – timer / 60 * 100) + time – timer)// 60​
where the // function = modulus divide to returns remainder is applied to all of the preceding calculation.
 
Last edited:
Top