Maths and coordinates problems

Hey,

I recently bought a 16x16 matrix screen with which I was going to attempt to make my own game of pong on. I had it all planned out, but when the screen arrived there was a problem which I did not think of. The WS2812B’s or the LED’s (whatever you want to call them) were arranged in a order which does not work with coordinate system that I had set up. In the image that I have attached you can see that above LED 15 is LED 16. The way I thought the LED’s would be set out is that LED 16 would be above LED 0 and continue from there, and that if LED 0 was on and you wanted to move the pixel up a row the number 16 would be added to the coordinate variable and the LED would move up one row. As you can tell if I used this method with the way these LED’s are set out, the pixel that is on would jump up a row and to the end.

Actual question

using maths is there a way to invert the second row to make 31 = 16, 16 = 31, 30 = 17, 17 = 30 and so on. Also the image only shows the first two rows, There are a total of 16 rows.

thanks

Heres a neat trick:

  1. attach your image and save your post,
  2. right click on the image and “copy image location”.
  3. Re-edit your post, click on the “insert image” icon in the tool bar and paste in the address from step 2.

Voila! Now its inline for everyone to see
f4453e06187c059dd759d9eb8076bfff78e0b137.png

Can you also publish your existing code(use the code tags!) so we know what co-ordinate system you are trying to use? I suspect its not hard but without the code its just speculation.

This is what I made to move a pixel across the screen.
I’m using the fastLED library to control the LEDs.
The only relevant part in the code to this post is the coordinates() function.

#include "FastLED.h"
#define NUM_LEDS 256
#define DATA_PIN 6
CRGB leds[NUM_LEDS];

int inputOne = 2;
int inputTwo = 4;
int inputThree = 3;
int inputFour = 5;
int pixelCoordinate = 0;
int oldLED = 0;
bool goLeft = false;
bool goUp = false;
bool goDown = false;
bool goRight = false;


void setup() 
{ 
  	  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
      pinMode(inputOne, INPUT);
      pinMode(inputTwo, INPUT);
      pinMode(inputThree, INPUT);
      pinMode(inputFour, INPUT);
}

void loop() 
{
  checkInput();
  coordinates();
  lightUpLEDs();
}

void checkInput()
{
  if (digitalRead(inputOne) == HIGH)
  {
    goLeft = true;
  }
  else
  {
    goLeft = false;
  }
    if (digitalRead(inputTwo) == HIGH)
  {
    goUp = true;
  }
  else
  {
    goUp = false;
  }
  if (digitalRead(inputThree) == HIGH)
  {
    goDown = true;
  }
  else
  {
    goDown = false;
  }
  if (digitalRead(inputFour) == HIGH)
  {
    goRight = true;
  }
  else
  {
    goRight = false;
  }
}

void coordinates()
{
  if (goLeft == true)
  {
    pixelCoordinate = pixelCoordinate - 1;
  }
  if (goUp == true)
  {
    pixelCoordinate = pixelCoordinate + 16;
  }
  if (goDown == true)
  {
    pixelCoordinate = pixelCoordinate - 16;
  }
  if (goRight == true)
  {
    pixelCoordinate = pixelCoordinate + 1;
  }
}

void lightUpLEDs()
{
  leds[oldLED] = CRGB(0,0,0);
  leds[pixelCoordinate] = CRGB(10,0,0);
  FastLED.show();
  oldLED = pixelCoordinate;               //This is to turn off a pixel once the coordinate has been changed.
}

I would address the array image shown in reply #1 as X from 0 to 15 (going to the right) and Y from 0 to 1 (going up).

Then pixel # = abs(31*Y - X)