9acca9
Posts: 13
Joined: Sun Sep 18, 2016 11:20 pm

From where this equations?

Mon Sep 09, 2019 7:06 pm

Hi all.
I just want to know from where he got this equations? (exact)
This:

Code: Select all

90   w=sq+1 # different numbering system
91   x =int((w-1)/3)+1   # anodes numbers starts 1
92   y =  (2+w)%3   # cathodes number start 0
https://github.com/mdobres/maxnox/blob/master/maxnox.py


thanks all!

cruster
Posts: 120
Joined: Mon Sep 01, 2014 7:56 pm

Re: From where this equations?

Mon Sep 09, 2019 7:12 pm

Contact him and ask him?

https://github.com/mdobres

Looks like he has a website:

http://chess.fortherapy.co.uk/home/

trejan
Posts: 1874
Joined: Tue Jul 02, 2019 2:28 pm

Re: From where this equations?

Mon Sep 09, 2019 7:20 pm

9acca9 wrote:
Mon Sep 09, 2019 7:06 pm
I just want to know from where he got this equations? (exact)
This:

Code: Select all

90   w=sq+1 # different numbering system
91   x =int((w-1)/3)+1   # anodes numbers starts 1
92   y =  (2+w)%3   # cathodes number start 0
Their code numbers the cells on the 3x3 board from 1 to 9 and those lines convert a cell number into X + Y coordinates to turn on/off a LED. They worked it out themselves as it is an implementation detail for their project and isn't anything complicated.

deepo
Posts: 574
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: From where this equations?

Mon Sep 09, 2019 7:22 pm

Looks like he is calculating x and y coordinates to where the LED is represented. So I guess it comes from the layout of the display.
Input is square number (zero based), and output is x and y (both zero based) in an 3x3 matrix.

/Mogens

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: From where this equations?

Mon Sep 09, 2019 9:46 pm

deepo wrote:
Mon Sep 09, 2019 7:22 pm
Looks like he is calculating x and y coordinates to where the LED is represented. So I guess it comes from the layout of the display.
Input is square number (zero based), and output is x and y (both zero based) in an 3x3 matrix.

/Mogens
[pedant] It looks like x is 1 based, not 0. Hence, the comments in the code. Why x and y should have different bases is anyone's guess. [/pedant]
Signature retired

deepo
Posts: 574
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: From where this equations?

Tue Sep 10, 2019 6:58 am

davidcoton wrote:
Mon Sep 09, 2019 9:46 pm
deepo wrote:
Mon Sep 09, 2019 7:22 pm
Looks like he is calculating x and y coordinates to where the LED is represented. So I guess it comes from the layout of the display.
Input is square number (zero based), and output is x and y (both zero based) in an 3x3 matrix.

/Mogens
[pedant] It looks like x is 1 based, not 0. Hence, the comments in the code. Why x and y should have different bases is anyone's guess. [/pedant]
You, sir, are correct.

hippy
Posts: 7459
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: From where this equations?

Tue Sep 10, 2019 11:55 am

I am not quite sure why the code doesn't just use the simpler -

Code: Select all

  x = (sq // 3) + 1
  y = sq % 3
But everyone has their 'off days', can struggle to get their mappings and manipulations to work, will often settle on 'that works, job done, on to the next problem'.

Return to “General discussion”