Modulus not working
in
Programming Questions
•
10 months ago
Hi everyone
I'm trying to create some software to drive a large flip dot display. I've got a good chunk of the code going, displaying as a black and white image in the middle of the frame.
I then split the image into an array of images for each panel to be processed. However trying to match the control spec is proving to be a challenge. Each byte is one strip (7 dots) of the sign. LSB is the most upper dot, MSB is the most lower dot. Bit number 8 is ignored.
I am thinking that the pixels[] location would return the value of the pixel as an int, which I can process directly or bit shift out, however it doesn't want to load the pixel information, returning the same value every time.
I'm trying to create some software to drive a large flip dot display. I've got a good chunk of the code going, displaying as a black and white image in the middle of the frame.
I then split the image into an array of images for each panel to be processed. However trying to match the control spec is proving to be a challenge. Each byte is one strip (7 dots) of the sign. LSB is the most upper dot, MSB is the most lower dot. Bit number 8 is ignored.
So I've made a modulus check to turn a buffer of 1's and 0's into a byte using the stringbuffer. And this will be collated into a frame to be sent outwards.
Where I'm stuck on though is I'm not able to read the pixel data correctly. The originalImg and splitImage transfer works without any problems, however the (r[index].pixels[newLoc])) checks to see if the pixel is black or white keeps returning the same result.
I am thinking that the pixels[] location would return the value of the pixel as an int, which I can process directly or bit shift out, however it doesn't want to load the pixel information, returning the same value every time.
void splitImage(PImage originalImg){
int index = 0;
int byteIndex = 0;
StringBuffer byteBuff = new StringBuffer();
byte[] data = new byte[112];
for (int ax = 0; ax < xcount; ax ++) { // Shifting panel width
for (int ay = 0; ay < ycount; ay ++) { // Shifting panel height
//Create image at coordinate (ax, ay) from the top left of the original image
r[index] = createImage(partWidth, partHeight, ARGB);
//Loop to copy pixels for each chunk
for (int px = 0; px < partWidth; px ++){
for (int py = 0; py < partHeight; py ++ ){
int newLoc = px + py * partWidth; // Create a 2d location of the array
int oldLoc = (ax * partWidth + px) + ((ay * partHeight+py)*xbound) ;
r[index].pixels[newLoc] = originalImg.pixels[oldLoc];
//PROBLEM AREA HERE
r[index].loadPixels();
//Convert the row of pixels into a string for byte conversion
//There are 7 bits before the byte resets
//We check the last bit, then append another byte onto the end for downstream processing.
//println(r[index].pixels[newLoc]);
if (byteBuff.length() == 7)
{
if (((r[index].pixels[newLoc])) != -31)
{
byteBuff.append("0");
} else {
byteBuff.append("1");
}
byteBuff.append("0");
byteBuff.reverse();
data[byteIndex] = byte(unbinary(byteBuff.toString()));
byteBuff.delete(0,byteBuff.length());
println(hex(data[byteIndex]));
byteIndex++;
//println("pop!");
} else {
if (((r[index].pixels[newLoc])) != -31)
{
byteBuff.append("0");
} else {
byteBuff.append("1");
}
}
}
}
index++;
byteIndex = 0;
}
}
}
I'm really starting to struggle debugging this too, as the output when I try to watch it quickly floods the message window and crashes the processing App. Is eclipse better for this? I think I've set the github stuff up right,
https://github.com/Smithjoe1/FlipDot for the full code set.
Thanks in advance!
1