static conts uint8_t PROGMEM Bitmap as Class Constructor Argument

Hi everyone,

This is my first time posting. i am new to programming/arduino and I’m having a bit of trouble getting my code to work the way I hoped it might. I have spent a lot of time searching for answers but i haven’t found an equivalent situation to borrow ideas from.

As part of a larger motorcycle speedo/dash project i’m working on i have set up a Class for the Sensor inputs [oil pressure, low, fuel, neutral, etc). Basically, using a LED metric [Adafruit_8x16minimatrix] I would like to have a different 8x8 bitmap icon come on for each sensor that is triggered.

So for each instance of the Class, I am using a series of uint8_t bitmaps as one of the Constructor Arguments. But i am unsure where to declare the bitmaps.

I would appreciate if someone could cast their eye over it and point out where um going wrong.

/*
  Sensor Program for Sensor Inputs

  This is for use with my motorcycle speedo/dash project.

  Created by Sean Griffiths, May 2, 2017.
  Released into the public domain.
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_8x16minimatrix matrix = Adafruit_8x16minimatrix();

//Class definition
class Sensor
{
  public:
  //declare public variables
     uint8_t _bmp;
  //constructor
  Sensor(int pin, int LED, long checkInt, uint8_t bmp, int x, int y);

  void begin();
  void update();
  
  //declare public variables
  private:
    //declare private variables
    unsigned long _previousMillis;
    unsigned long _currentMillis;

    int _pin;
    int _LED;             //LED for testing purposes [remove in final version]]
    long _checkInt;                   
   
    int _x;                          
    int _y;
    
    int _sensorState;
    int _LEDstate;        //LED for testing purposes [remove in final version]]
    
};

//Member definitions

  //Constructor
  Sensor::Sensor(int pin, int LED, long checkInt, uint8_t bmp, int x, int y)
  {
    _pin = pin;
    _LED = LED;
    _checkInt = checkInt;
    _bmp = bmp;
    _x = x;
    _y = y;  
  }

  void Sensor::begin()
  {
    pinMode(_pin, INPUT_PULLUP);
    pinMode(_LED, OUTPUT);           //LED for testing purposes [remove in final version]                             
  }
                                 
  void Sensor::update()  
  {
    _sensorState = digitalRead(_pin);// 'Input_pullup' means the input's
                                     // logic is inverted. It goes HIGH when it's open,
                                     // and LOW when it's pressed.
      
    // check to see if it's time to check the state of the Input      
    if(_currentMillis - _previousMillis >= _checkInt)
      {
        if(_sensorState == HIGH)
        {    
          Serial.println("no inputs");              //for testing purposes [remove in final version]
          digitalWrite(_LED, !_LEDstate);           //for testing purposes [remove in final version]
            
          matrix.drawBitmap(_x, _y, _bmp, 8, 8, LED_OFF);//display 'negative' icon on matrix display - NOTE LED_'OFF'
          matrix.writeDisplay();
        }                                           //close if-statement
        else 
        {
          Serial.println("a sensor has tripped!");  //for testing purposes [remove in final version]
          digitalWrite(_LED, !_LEDstate);           //for testing purposes [remove in final version]
            
          matrix.drawBitmap(_x, _y, _bmp, 8, 8, LED_ON); //display icon on matrix display
          matrix.writeDisplay();           
        }                                           //close else-statement
      }                                             //close if-statement
  }                                                 //close 'Update'
}                                                   //close Class

static const uint8_t PROGMEM                        //THIS IS WHAT IM HAVING PROBLEMS WITH
    oilBMP[] = 
      { B00000000,
        B01111110,
        B01000010,
        B01000010,
        B01000010,
        B01000010,
        B01111110,
        B00000000
       };
    static const uint8_t PROGMEM
    neutralBMP[] = 
      { B11111111,
        B10000001,
        B10111101,
        B10111101,
        B10111101,
        B10111101,
        B10000001,
        B11111111
      };
      
Sensor oil(2, 11, 250, oil_BMP, 0,0);               //the pin number of the oil sensor input pin, LED pin, check frequency, icon bitmap, cursor x & cursor y
Sensor neutral(3, 12, 250, neutral_BMP,8,0);        //the pin number of the oil sensor input pin, LED pin, check frequency & icon bitmap, cursor x & cursor y
 
void setup()
{
  Serial.begin(9600);                               //for communication with computer & LED matrix display
  
  matrix.begin(0x70);                               // matrix display address
  matrix.clear();                                   // clear the display

  oil.begin();
  neutral.begin();
}

void loop()
{
  oil.update();
  neutral.update();
}

and point out where um going wrong.

Well, for one thing, you appear to have you class definition, class implementation, and sketch all in one file. Bad idea. Use three files.

static const uint8_t PROGMEM                        //THIS IS WHAT IM HAVING PROBLEMS WITH

Knowing that you are having problems is useless without knowing WHAT the problems are. Why do you need to declare global variables static?

I'm guessing that the compiler objects because you are passing the address of an array into a byte. Your 'bmp' and '_bmp' should probably be declared "uint8_t *" rather than "uint8_t".