Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // translates from x, y into an index into the LED array and
- // finds the right index for a S shaped matrix
- int XY(int x, int y) {
- if(y > HEIGHT) {
- y = HEIGHT;
- }
- if(y < 0) {
- y = 0;
- }
- if(x > WIDTH) {
- x = WIDTH;
- }
- if(x < 0) {
- x = 0;
- }
- // for a serpentine layout reverse every 2nd row:
- if(x % 2 == 1) {
- return (x * (WIDTH) + (HEIGHT - y -1));
- }
- else {
- // use that line only, if you have all rows beginning at the same side
- return (x * (WIDTH) + y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment