Guest User

Untitled

a guest
Dec 21st, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. // translates from x, y into an index into the LED array and
  2. // finds the right index for a S shaped matrix
  3. int XY(int x, int y) {
  4. if(y > HEIGHT) {
  5. y = HEIGHT;
  6. }
  7. if(y < 0) {
  8. y = 0;
  9. }
  10. if(x > WIDTH) {
  11. x = WIDTH;
  12. }
  13. if(x < 0) {
  14. x = 0;
  15. }
  16. // for a serpentine layout reverse every 2nd row:
  17. if(x % 2 == 1) {
  18. return (x * (WIDTH) + (HEIGHT - y -1));
  19. }
  20. else {
  21. // use that line only, if you have all rows beginning at the same side
  22. return (x * (WIDTH) + y);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment