LED Matrix change pictogram forward and backward

Hi everyone,
I have a LED Matrix and 2 buttons on digital pins 3 and 4 and three pictogram's (icons) A,B,C (will be more than 3) to scroll trough by pressing button 1 (display next or forward) or 2 (display previous or backward).
With help on a old thread I manage to use button 1 to display the pictogram's from A to B to C for each press but I want to implement the button 2 to display the pictogram's on the reverse order.

Here is the code I have:

/*
This example code is in the public domain.

http://arduino.cc/en/Tutorial/ButtonStateChange

*/
//#include <TinyWireM.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

const int button1Pin = 3;    // button pin on RePhone pad A1
const int button2Pin = 4;    // button pin on RePhone pad E2
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

// Variables will change:
int button1PushCounter = 0;   // counter for the number of button1 presses
int button1State = 0;         // current state of the button1
int lastButton1State = 0;     // previous state of the button1

int button2PushCounter = 0;   // counter for the number of button2 presses
int button2State = 0;         // current state of the button2
int lastButton2State = 0;     // previous state of the button2

void setup() {
  // initialize the button pin as a input:
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  matrix.begin(0x70);     // pass in the address
}

static const uint8_t PROGMEM   // X and square bitmaps
smile_bmp[] =
{ B00111100,
  B01000010,
  B10100101,
  B10000001,
  B10100101,
  B10011001,
  B01000010,
  B00111100
},
hearth_bmp[] =
{ B00100100,
  B01011010,
  B10011001,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000
},
flower_bmp[] =
{ B11000011,
  B10100101,
  B01100110,
  B00011000,
  B01111011,
  B10101110,
  B11001100,
  B00001000
};

void loop() {
  // read the pushbutton input pin:
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);
  // compare the buttonState to its previous state
  if (button1State != lastButton1State) {
    // if the state has changed, increment the counter
    if (button1State == HIGH && lastButton1State == LOW) {
      // if the current state is HIGH then the button
      // went from off to on:
      button1PushCounter++;
    } else {
      if (button1State != lastButton1State) {
        // if the state has changed, increment the counter
        if (button2State == HIGH && lastButton2State == LOW) {
          // if the current state is HIGH then the button
          // went from off to on:
          button2PushCounter--;
        }
      }
      // save the current state as the last state,
      //for next time through the loop
      lastButton1State = button1State;
      lastButton2State = button2State;

      // turns on the LED every four button pushes by
      // checking the modulo of the button push counter.
      // the modulo function gives you the remainder of
      // the division of two numbers:
      switch (button1PushCounter % 3)
      {
        case 0:
          matrix.clear();
          matrix.drawBitmap(0, 0, hearth_bmp, 8, 8, LED_ON);
          matrix.writeDisplay();
          button1State = HIGH;
          break;
        case 1:
          matrix.clear();
          matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
          matrix.writeDisplay();
          button1State = HIGH;
          break;
        case 2:
          matrix.clear();
          matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
          matrix.writeDisplay();
          button1State = HIGH;
      }
    }

Here is how I interpret in my logic (poor brain):
Variables are keeping track of the button presses for each buton

// Variables will change:
int button1PushCounter = 0;   // counter for the number of button1 presses
int button1State = 0;         // current state of the button1
int lastButton1State = 0;     // previous state of the button1

int button2PushCounter = 0;   // counter for the number of button2 presses
int button2State = 0;         // current state of the button2
int lastButton2State = 0;     // previous state of the button2

and I should use somehow this button2PushCounter--; to display the previous pictogram when button 2 is pressed. It works great in one direction but I can not make it to go to previous with button 2 press.

So I have a variable Counter that keeps track of button presses and now when I detect a button 2 press should change the number in Counter variable by -1 and then draw on the matrix the corresponding pictogram ...

Any hint or help is appreciated.
Thanks!

You only need one buttonPushCounter not two. Then you can use the switch/case as it is.

So, instead of

button2PushCounter--;

try

buttonPushCounter--;

Change the declaration of buttonPushCounter to an unsigned int to prevent it going negative when it goes below zero.

Thank you!
Here is the running code:

/*
This example code is in the public domain.

http://arduino.cc/en/Tutorial/ButtonStateChange

*/
//#include <TinyWireM.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

const int button1Pin = 3;    // button pin on RePhone pad A1
const int button2Pin = 4;    // button pin on RePhone pad E2
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of buttons presses
int button1State = 0;         // current state of the button1
int lastButton1State = 0;     // previous state of the button1

//int button2PushCounter = 0;   // counter for the number of button2 presses
int button2State = 0;         // current state of the button2
int lastButton2State = 0;     // previous state of the button2

void setup() {
  // initialize the button pin as a input:
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  matrix.begin(0x70);     // pass in the address
}

static const uint8_t PROGMEM   // X and square bitmaps
smile_bmp[] =
{ B00111100,
  B01000010,
  B10100101,
  B10000001,
  B10100101,
  B10011001,
  B01000010,
  B00111100
},
hearth_bmp[] =
{ B00100100,
  B01011010,
  B10011001,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000
},
flower_bmp[] =
{ B11000011,
  B10100101,
  B01100110,
  B00011000,
  B01111011,
  B10101110,
  B11001100,
  B00001000
};

void loop() {
  // read the pushbutton input pin:
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);
  // compare the buttonState to its previous state
  if (button1State != lastButton1State) {
    // if the state has changed, increment the counter
    if (button1State == HIGH && lastButton1State == LOW) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter++;
    } else {
      // if the current state is LOW then the button
      // went from on to off:
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButton1State = button1State;

  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  switch (buttonPushCounter % 3)
  {
    case 0:
      matrix.clear();
      matrix.drawBitmap(0, 0, hearth_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      button1State = HIGH;
      break;
    case 1:
      matrix.clear();
      matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      button1State = HIGH;
      break;
    case 2:
      matrix.clear();
      matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      button1State = HIGH;
  }

  if (button2State != lastButton2State) {
    // if the state has changed, increment the counter
    if (button2State == HIGH && lastButton2State == LOW) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter--;
    } else {
      // if the current state is LOW then the button
      // went from on to off:
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButton2State = button2State;
}

Good for you in getting it working. Now, can you improve it ?

There are things that you can do to the code that won't make it work any better but could be useful techniques to use in larger programs later.

Firstly, look at all of the variables in the program. Are they of the appropriate type ? For instance do the buttonPin variables have to be ints or would bytes be big enough ? The same with the state variables. Save memory where you can as it is precious.

How about the names of the variables ? Right now button1 and button2 mean something to you but not me without looking at the code. It might be better to give them more logical names such as upButton and downButton so that when you read the code in 6 months you are reminded of their functions.

When you added the code to handle the second button you put it at the end of the code. There is nothing wrong with that but it is dissociated from the button1 code and even from the button 2 reading of its state. Personally I would have put all of the button reading code together and maybe even put it in a function with a meaningful name and maybe the same for the block of code that updates the display.

Currently the display is updated every time through loop() which is not very efficient. How about updating it only when the value of buttonPushCounter has changed ? Isolating the update code into a function would make this neater.

When the display is updated there is a degree of common code in each case block. How about creating a function to do

      matrix.clear();
      matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      button1State = HIGH;

and passing the name of the array to it ? Incidentally, do you need to set the state of the button at this stage ?

A small thing, but there is at least one place in the code where the comments do not match the code

    // if the state has changed, increment the counter
    if (button2State == HIGH && lastButton2State == LOW) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter--;

Cut and paste strikes again. As I say, a small thing, but untidy and it could be confusing in a larger program.

I bet you jumped when you saw how much I had to say about your working program, but using best practices will serve you well in the long run and if you experiment with the techniques with small programs it is easier to keep track of what is going on.

Good luck with your future projects.

Dear UKHeliBob,
thank you so much for the help and the homework (Now, can you improve it ?)

Definitely working to improve the code and build up my skills. My code is a bit of a mess because I do copy paste from other posts trying to improve on that or to build up from others base since I know nothing about coding.
For instance yesterday after reading your post I went to read what are functions and see how can I understand and use them (basically they are a block of code with an assigned name that I can call later on where and when needed)
You are saying something about ARRAYS but I was never able to really understand them so this will be hard for me to figure it out ... I see ARRAYS as a variable with more than one key in it [1,3,5] but I do not understand how they work at all. And for me a variable is a "box" with "n apples" in it.
And one more thing about this statement

Currently the display is updated every time through loop() which is not very efficient.  How about updating it only when the value of buttonPushCounter has changed ?  Isolating the update code into a function would make this neater.

If I am not wrong the code is executed in the loop() infinitely, this is how Arduino works so where/how do I put the code out of loop() and run only when needed?

Thank you! and please feed me with infos (I did not jumped, actually I was glad to see someone involved in my programming efforts)

Regards,
Catalin

I went to read what are functions and see how can I understand and use them (basically they are a block of code with an assigned name that I can call later on where and when needed)

Correct. There are a number of reasons why you might want to use functions, in fact you already are. For instance, pinMode() is a function.

Functions allow you to give a block of code a meaningful name that can be executed (called) once or more times in a program. As an extension to this you can pass parameters to functions if required so that they do something similar but different, such as the pin number and mode passed to pinMode(). So, you could create a function to draw a pictogram and pass the name of the array holding the pictogram to the function.
Thus avoiding writing the same code several times.

You are already using arrays in your program. The pictograms are arrays of binary numbers and each one holds data for each row of the picture. You access data in an array by referring to a row by its index number, starting at zero. Although the intricacies of

matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);

are hidden from you (you can see it if you want) it is a fair bet that the function works its way through the array row by row (0 to 7) and column by column (0 to 7) across the bits of each byte.

If I am not wrong the code is executed in the loop() infinitely, this is how Arduino works

That is correct in general but does not have to be true in all cases but that is not what I was suggesting. Once a pictogram has been drawn there is no need to draw it again unless/until buttonPushCounter has changed. So in pseudo code you would do something like this

start of loop()
  read inputs and update buttonPushCounter if a button is pressed
  if buttonPushCounter is not equal to previousButtonPushCounter
    draw the picture
  end if
  save buttonPushCounter to variable previousButtonPushCounter 
end of loop()

Hi HeliBob,

I went trough my code and rearranged a bit (change the variable types from int to byte, yes it reduced the mem. used)
Here comes the code v2

/*
This example code is in the public domain.

http://arduino.cc/en/Tutorial/ButtonStateChange

*/
//#include <TinyWireM.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

const byte button_Next_onPin = 3;    // button pin on RePhone pad A1 (display next icon)
const byte button_Previous_onPin = 4;    // button pin on RePhone pad E2 (display previous icon)
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

// Variables will change:
byte buttonPushCounter = 0;   // counter for the number of buttons presses
// Variables for Next and Previous button push controll
byte buttonNextState = 0;         // current state of the button Next
byte lastButtonNextState = 0;     // previous state of the button Next
byte buttonPreviousState = 0;         // current state of the button Previous
byte lastButtonPreviousState = 0;     // previous state of the button Previous

void setup() {
  // initialize the button pin as a input:
  pinMode(button_Next_onPin, INPUT);
  pinMode(button_Previous_onPin, INPUT);
  matrix.begin(0x70);     // pass in the address
}

static const uint8_t PROGMEM   // the icon's byte array definition
smile_bmp[] =
{ B00111100,
  B01000010,
  B10100101,
  B10000001,
  B10100101,
  B10011001,
  B01000010,
  B00111100
},
hearth_bmp[] =
{ B00100100,
  B01011010,
  B10011001,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000
},
flower_bmp[] =
{ B11000011,
  B10100101,
  B01100110,
  B00011000,
  B01111011,
  B10101110,
  B11001100,
  B00001000
};

void loop() {
  // read the pushbutton Next and Previous input pin:
  buttonNextState = digitalRead(button_Next_onPin);
  buttonPreviousState = digitalRead(button_Previous_onPin);

  // compare the buttonNextState to its previous state
  if (buttonNextState != lastButtonNextState) {
    // if the state has changed, increment the counter
    if (buttonNextState == HIGH && lastButtonNextState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
    } else {
      // if the current state is LOW then the button went from on to off:
    }
  }
  // save the current state as the last state, for next time through the loop
  lastButtonNextState = buttonNextState;

  // compare the buttonPreviousState to its previous state
  if (buttonPreviousState != lastButtonPreviousState) {
    // if the state has changed, increment the counter
    if (buttonPreviousState == HIGH && lastButtonPreviousState == LOW) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter--;
    } else {
      // if the current state is LOW then the button went from on to off:
    }
  }
  // save the current state as the last state, for next time through the loop
  lastButtonPreviousState = buttonPreviousState;

  // turns on the LED every four button pushes by checking the modulo of the button push counter.
  // the modulo function gives you the remainder of the division of two numbers:
  switch (buttonPushCounter % 3)
  {
    case 0:
      matrix.clear();
      matrix.drawBitmap(0, 0, hearth_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
      break;
    case 1:
      matrix.clear();
      matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
      break;
    case 2:
      matrix.clear();
      matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
  }
}

I started this due to Adafruit learning site which holds great informations and gradually working my way trough ... and here is what I would like to implement in my sketch also: I understand by different posts that using PROGMEM is a good thing which I already kind of use it for storing my BMP icons in the arrays.
I created a new tab "icons_BMP" to structure better my main sketch and keep all the icons there, moved my icons array there but I get an error at compile that I do not know how to tackle:
error: sketch_Matrix1_tab.ino:11:23: fatal error: icons_BMP.h: No such file or directory

Here is the code v3 with the tabs (sketch_Matrix1_tab)

/*
This example code is in the public domain.

http://arduino.cc/en/Tutorial/ButtonStateChange

*/
//#include <TinyWireM.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "icons_BMP.h"

const byte button_Next_onPin = 3;    // button pin on RePhone pad A1 (display next icon)
const byte button_Previous_onPin = 4;    // button pin on RePhone pad E2 (display previous icon)
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

// Variables will change:
byte buttonPushCounter = 0;   // counter for the number of buttons presses
// Variables for Next and Previous button push controll
byte buttonNextState = 0;         // current state of the button Next
byte lastButtonNextState = 0;     // previous state of the button Next
byte buttonPreviousState = 0;         // current state of the button Previous
byte lastButtonPreviousState = 0;     // previous state of the button Previous

void setup() {
  // initialize the button pin as a input:
  pinMode(button_Next_onPin, INPUT);
  pinMode(button_Previous_onPin, INPUT);
  matrix.begin(0x70);     // pass in the address
}

static const uint8_t PROGMEM   // the icon's byte array definition

void loop() {
  // read the pushbutton Next and Previous input pin:
  buttonNextState = digitalRead(button_Next_onPin);
  buttonPreviousState = digitalRead(button_Previous_onPin);

  // compare the buttonNextState to its previous state
  if (buttonNextState != lastButtonNextState) {
    // if the state has changed, increment the counter
    if (buttonNextState == HIGH && lastButtonNextState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
    } else {
      // if the current state is LOW then the button went from on to off:
    }
  }
  // save the current state as the last state, for next time through the loop
  lastButtonNextState = buttonNextState;

  // compare the buttonPreviousState to its previous state
  if (buttonPreviousState != lastButtonPreviousState) {
    // if the state has changed, increment the counter
    if (buttonPreviousState == HIGH && lastButtonPreviousState == LOW) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter--;
    } else {
      // if the current state is LOW then the button went from on to off:
    }
  }
  // save the current state as the last state, for next time through the loop
  lastButtonPreviousState = buttonPreviousState;

  // turns on the LED every four button pushes by checking the modulo of the button push counter.
  // the modulo function gives you the remainder of the division of two numbers:
  switch (buttonPushCounter % 3)
  {
    case 0:
      matrix.clear();
      matrix.drawBitmap(0, 0, hearth_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
      break;
    case 1:
      matrix.clear();
      matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
      break;
    case 2:
      matrix.clear();
      matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
  }
}

the BMP tab (icons_BMP)

static const uint8_t PROGMEM bmp[] = {  // the icon's byte array definition

//smile_bmp[] =
 B00111100,
  B01000010,
  B10100101,
  B10000001,
  B10100101,
  B10011001,
  B01000010,
  B00111100,

//hearth_bmp[] =
B00100100,
  B01011010,
  B10011001,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000,

//flower_bmp[] =
 B11000011,
  B10100101,
  B01100110,
  B00011000,
  B01111011,
  B10101110,
  B11001100,
  B00001000,

};

In Adafruit example they just #include the name of the tab at the beginning of main sketch and that is it ....

Well the PROGMEM and TAB thing I can look at later on when my programming skills are be better till any recommendation on my rearranged pcs. of code?

Thanks!

I created a new tab "icons_BMP"

Is that the full name of the file ? I ask because in your code you have

#include "icons_BMP.h"

My tab name is icons_BMP and I use #include "icons_BMP.h" because I see others using it in that form.
I just replace the tab name with icons_BMP.h and now I get another error:

sketch_Matrix1_tab.ino:17:11: error: two or more data types in declaration of 'loop'
sketch_Matrix1_tab.ino:34:11: error: two or more data types in declaration of 'loop'
Error compiling.

any hint? I should replace somehow the switch/case block because it is calling the icons by name and they have no name now in the icons_BMP.h tab

switch (buttonPushCounter % 3)
  {
    case 0:
      matrix.clear();
      matrix.drawBitmap(0, 0, hearth_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
      break;
    case 1:
      matrix.clear();
      matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
      break;
    case 2:
      matrix.clear();
      matrix.drawBitmap(0, 0, flower_bmp, 8, 8, LED_ON);
      matrix.writeDisplay();
      buttonNextState = HIGH;
  }
}

they have no name now in the icons_BMP.h tab

Why not ?
Can you please post the full program and the full .h file

Bob,
I posted the full code for the main tab and the icons_BMP.h tab above under code v3 post (two posts above).
I was guiding myself by Adafruit tutorial and on their second tab they have no names for the arrays but they have this declaration on main tab that I do not understand what it does or if I should do the same thing.
Also I am not using an Arduino board just coding in arduino IDE for RePhone (by SeedStudio).
This is the chunk of code from Adafruit tut. that I do not understand what it does but is related to their 2'nd tab that contains the LED Matrix animation which is accessed somehow in their main tab code:

static const uint8_t PROGMEM reorder[] = { // Column-reordering table
    0x00,0x40,0x20,0x60,0x10,0x50,0x30,0x70,0x08,0x48,0x28,0x68,0x18,0x58,0x38,0x78,
    0x04,0x44,0x24,0x64,0x14,0x54,0x34,0x74,0x0c,0x4c,0x2c,0x6c,0x1c,0x5c,0x3c,0x7c,
    0x02,0x42,0x22,0x62,0x12,0x52,0x32,0x72,0x0a,0x4a,0x2a,0x6a,0x1a,0x5a,0x3a,0x7a,
    0x06,0x46,0x26,0x66,0x16,0x56,0x36,0x76,0x0e,0x4e,0x2e,0x6e,0x1e,0x5e,0x3e,0x7e,
    0x01,0x41,0x21,0x61,0x11,0x51,0x31,0x71,0x09,0x49,0x29,0x69,0x19,0x59,0x39,0x79,
    0x05,0x45,0x25,0x65,0x15,0x55,0x35,0x75,0x0d,0x4d,0x2d,0x6d,0x1d,0x5d,0x3d,0x7d,
    0x03,0x43,0x23,0x63,0x13,0x53,0x33,0x73,0x0b,0x4b,0x2b,0x6b,0x1b,0x5b,0x3b,0x7b,
    0x07,0x47,0x27,0x67,0x17,0x57,0x37,0x77,0x0f,0x4f,0x2f,0x6f,0x1f,0x5f,0x3f,0x7f,
    0x80,0xc0,0xa0,0xe0,0x90,0xd0,0xb0,0xf0,0x88,0xc8,0xa8,0xe8,0x98,0xd8,0xb8,0xf8,
    0x84,0xc4,0xa4,0xe4,0x94,0xd4,0xb4,0xf4,0x8c,0xcc,0xac,0xec,0x9c,0xdc,0xbc,0xfc,
    0x82,0xc2,0xa2,0xe2,0x92,0xd2,0xb2,0xf2,0x8a,0xca,0xaa,0xea,0x9a,0xda,0xba,0xfa,
    0x86,0xc6,0xa6,0xe6,0x96,0xd6,0xb6,0xf6,0x8e,0xce,0xae,0xee,0x9e,0xde,0xbe,0xfe,
    0x81,0xc1,0xa1,0xe1,0x91,0xd1,0xb1,0xf1,0x89,0xc9,0xa9,0xe9,0x99,0xd9,0xb9,0xf9,
    0x85,0xc5,0xa5,0xe5,0x95,0xd5,0xb5,0xf5,0x8d,0xcd,0xad,0xed,0x9d,0xdd,0xbd,0xfd,
    0x83,0xc3,0xa3,0xe3,0x93,0xd3,0xb3,0xf3,0x8b,0xcb,0xab,0xeb,0x9b,0xdb,0xbb,0xfb,
    0x87,0xc7,0xa7,0xe7,0x97,0xd7,0xb7,0xf7,0x8f,0xcf,0xaf,0xef,0x9f,0xdf,0xbf,0xff };

If you can guide me on fixing my code to access the icons_BMP to fetch the data from there fine, if not there is a lot to do on my side with my standard code and optimise it later on when Ill have more experience ...

Thank you! and please bear with me ...

sketch_Matrix1_tab.ino (3.1 KB)

icons_BMP.h (454 Bytes)

I don't understand why you have commented out the names of the arrays in the .h file. Start with the program that works and cut the array definitions out of it an put them in the .h file. Put the #include for the .h file in your main program and compile it. What happens ?

You can have one big array with all of the pictograms in but don't do it, certainly not at the moment.

Thank you!!!
well it compiles with no errors of course. (need to upload on the hardware and see it in action later on today)
I am working on my previous homework as / your pseudo:

start of loop()
  read inputs and update buttonPushCounter if a button is pressed
  if buttonPushCounter is not equal to previousButtonPushCounter
    draw the picture
  end if
  save buttonPushCounter to variable previousButtonPushCounter 
end of loop()

Ill post soon ...

Regards,
Catalin

icons_BMP.h (745 Bytes)

sketch_Matrix1_tab.ino (3.03 KB)

Advice or help needed, please.
I added more to my code so that now I can communicate with the LED Matrix via SMS but I am stuck on the following: when a predefined SMS is received "GPS" text in my case I want to get back the value contained by a variable. I can get a predefined text as a reply but I want to read the content of a variable and not a predefined txt.
Below the chunk of code that reply the predefined txt but not the vaeriable "buttonPushCounter" content

  if (LSMS.available())                                              // if received a SMS from another cellphone
  {
    LSMS.remoteNumber(num, 20);
    LSMS.remoteContent(buf_contex, 50);

    sprintf(buffer, "Get new sms, content: %s, number: %s \r\n", buf_contex, num);
    Serial.println(buffer);

    if (strcmp("GPS", (char*)buf_contex) == 0)                     // if the SMS content is 'GPS', then send the GPS information of RePhone back to the sender
    {

      //change var "buttonPushCounter" with "txt" to be automatically sent back when sms with GPS text is received
      sprintf(buffer, "buttonPushCounter", buttonPushCounter = 0);
      Serial.println(buffer);

      if (LSMS.ready())
      {
        LSMS.beginSMS(num);
        LSMS.print(buffer);

        if (LSMS.endSMS()) Serial.println("SMS sent ok!");
        else Serial.println("SMS send fail!");
      }
      else Serial.println("SMS no ready!");
    }
  }
  LSMS.flush();
  //}

Thank you!

      sprintf(buffer, "buttonPushCounter : %d", buttonPushCounter);

Thak you!
In my code the between quotes "xxx" it gets sent back as a plain text.

sprintf(buffer, "buttonPushCounter", buttonPushCounter = 0);

on your line you added "xxxx : %d", how is that not still a predefined text line ? what is the : %d ?
and then I see you added the variable buttonPushCounter as the last parameter which contains what I need to get.

Is it that you say: when SMS received reply the text "buttonPushCounter and space and the content of variable" ?

Regards!

what is the : %d

It's a place marker for where a variable is to be inserted
The variable to be inserted is buttonPushCounter

The number (and type) of place markers must match the number (and type) of the data items.

See printf

Why the below code does not send the SMS when button is pressed?

  //added by me to send SMS if button Send is pressed #########################################
  buttonSendState = digitalRead(button_Send_onPin);
  if (buttonSendState != lastButtonSendState) {
    if (buttonSendState == HIGH && lastButtonSendState == LOW) {
      buttonSendCounter++;
    } else {
  if (LSMS.ready())
  {
    LSMS.beginSMS(numSend);
    LSMS.print("button Send pressed");
  }
  LSMS.flush();
    }
  }
  lastButtonSendState = buttonSendState;
  
  //###########################################################################################

I do not understand, the buttonSendCounter works, I send a SMS to it and the automatic reply gives me the content of buttonSendCounter correctly so I know the button is wired correctly and the code reads the button presses in the variable.
I can not make it send a SMS to me (predefined nr.) when the button is pressed.

Any help or guidance is appreciated, thank you!

You are carefully checking to see whether the button has become pressed but all you do if it has is to increment the counter. Don't you want to send an SMS if the button has become depressed.

Sure I want to send the SMS :slight_smile:

Now I have this and still no SMS is sent :frowning:

  //#########################################

  buttonSendState = digitalRead(button_Send_onPin);
  if (buttonSendState != lastButtonSendState) {
    if (buttonSendState == HIGH && lastButtonSendState == LOW) {
      buttonSendCounter++;
      if (LSMS.ready())
      {
        LSMS.beginSMS(numSend);
        LSMS.print("button Send pressed");
      }
      LSMS.flush();

    } else {

    }
  }
  lastButtonSendState = buttonSendState;

  //###########################################################

I know I am close but some how my mistake is where I put (place in code) the SMS function part:

if (LSMS.ready())
      {
        LSMS.beginSMS(numSend);
        LSMS.print("button Send pressed");
      }
      LSMS.flush();

I changed the location of it everywhere made sense to me but never got a SMS from the button press