Give method an array of bytes

Hi there!

Lets say Ive got this piece of byte array:

static const byte someData[][5] = {
 {B11110000, B01010000, B11110000, B00000000, B00000000}
,{B11110011, B01011110, B11110000, B00010001, B00001111}};

And I want to give a certain array in the array to another method:

void drawString(char *text, int x, int y)
{
  int bpp, bi, xi, yi;
  xi = x;
  yi = y;
  while(*text)
  {
    char character = *text++;
    byte charBitmap = someData[character - 0x20]; // should be an array of 5 bytes!
    drawBitmap(xi,y,charBitmap,5,8);
    xi += 6;
  }
}

void drawBitmap(int x, int y, byte *bitmap[], int height, int width)
{
  int xi = x;
  int yi = y;
  for(int i = 0; i < 5; i++) 
  {
    byte bitmapByte = bitmap[i];
    Serial.println(bitmapByte,BIN);
    yi = y;
    xi += 1;
    for(int u = 0;u < 8; u++)
    {
      bool pixelState = bitRead(bitmapByte,u);
      if(pixelState == 1)
      {
        drawPixel(xi,yi);
      } else {
        // Nothing, clear pixel?
      }
      yi += 1;
    }
  }
}

Here bitmapByte does not output the bytes that are on the specified position. Just gibberish.
If I put the drawBitmap method INSIDE the drawString method it works fine. So I think the problem is how I transfer the byte array from the someData[0] to the charBitmap.

So how to transfer the sub byte array to the method?

Thanks in advance!

The function drawBitmap you've defined expects an array of byte pointers as it's third argument. When you call it from drawString you provide as the third argument a single byte variable. I'm not sure what you expect to have happen there.

You're going to have to dispense with the handwaving and provide a minimal example that compiles and runs and presents the problem along with what output you expect and what output you observe.

“byte *bitmap” is the same as “byte **bitmap”, use “byte *bitmap” instead.

Thanks for your replies.

With the following code:

static const byte someData[][5] = {
 {B11110000, B01010000, B11110000, B00000000, B00000000}
,{B11110011, B01011110, B11110000, B00010001, B00001111}};

byte arrayOfBytes = someData[1];
drawBitmap(5,5,arrayOfBytes,5,1);

I want this output:

B11110011
B01011110
B11110000
B00010001
B00001111

But I get:

B0000000
B11111100
B00000010
B00010001
B00000000

So I get not the right byte array there... :(

You are assigning an array (someData[1]) to a byte (arrayOfBytes) which cannot work.

byte *theBitmap = someData[1];
drawBitmap(5,5,theBitmap,5,1);
//OR simply
drawBitmap(5,5,someData[1],5,1);

Use C++ array references:

[color=#00979c]const[/color] [color=#00979c]byte[/color] [color=#000000]([/color][color=#434f54]&[/color][color=#000000]arrayOfBytes[/color][color=#000000])[/color][color=#000000][[/color][color=#000000]5[/color][color=#000000]][/color] [color=#434f54]=[/color] [color=#000000]someData[/color][color=#000000][[/color][color=#000000]1[/color][color=#000000]][/color][color=#000000];[/color]
Code:





```
static const byte someData[][5] = {

{B11110000, B01010000, B11110000, B00000000, B00000000},
 {B11110011, B01011110, B11110000, B00010001, B00001111}
};

void drawPixel(int x, int y) { }

void drawString(char *text, int x, int y)
{
 int bpp, bi, xi, yi;
 xi = x;
 yi = y;
 while color=#000000[/color]
 {
   char character = *text++;
   const byte color=#000000[/color][5] = someData[character - 0x20]; // should be an array of 5 bytes!
   drawBitmap(xi, y, charBitmap, 5, 8);
   xi += 6;
 }
}

void drawBitmap(int x, int y, const byte color=#000000[/color][5], int height, int width)
{
 int xi = x;
 for (int i = 0; i < 5; i++)
 {
   byte bitmapByte = bitmap[i];
   int yi = y; // Are you sure that it shouldn’t be the other way around?
   xi += 1;
   whilecolor=#000000[/color] {
     boolean pixelState = bitmapByte & 0x80;
     Serial.printcolor=#000000[/color];
     if color=#000000[/color]
       drawPixel(xi, yi);
     yi += 1;
     bitmapByte <<= 1;
   }
   Serial.printlncolor=#000000[/color];
 }
}

void setupcolor=#000000[/color] {
 Serial.begincolor=#000000[/color];
 whilecolor=#000000[/color];

const byte color=#000000[/color][5] = someData[1];
 drawBitmapcolor=#000000[/color];
}

void loopcolor=#000000[/color] { }
```

|

Pieter

Thank you guys for your help! It works now! :) Learned something! :)