Hi everyone, it has been a long while since I gave up my current project but as it is holidays, I have more time to do Arduno stuff. But my current problem is still not solved and after having spent few hours today trying to find the solution, I am saturated enough to give up and ask for some help here.
As you will read in the code, I am trying to call for a function in the void loop when I push the button.
My willing is to have the function "standby()" to loop, then I push the button and the function "transformation1()" is called UNTIL i push again the button to stop it and back in "standby()".
I watched some tutorials and messages in this forum but nothing seems to answer my trouble.
It seems simple but I am truly unable to find...
Here my code :
// Program to exercise the MD_MAX72XX library
//
// Uses most of the functions in the library
#include <MD_MAX72xx.h>
//#include <SPI.h>
// Turn on debug statements to the serial output
#define DEBUG 1
#if DEBUG
#define PRINT(s, x) { Serial.print(F(s)); Serial.print(x); }
#define PRINTS(x) Serial.print(F(x))
#define PRINTD(x) Serial.println(x, DEC)
#else
#define PRINT(s, x)
#define PRINTS(x)
#define PRINTD(x)
#endif
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW
#define MAX_DEVICES 11
#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS
int BUTTON_PINL = 4;
//int BUTTON_PINR = 3;
// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
// MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
// We always wait a bit between updates of the display
#define DELAYTIME 100 // in milliseconds
void setup()
{
pinMode(BUTTON_PINL, INPUT_PULLUP);
//pinMode(BUTTON_PINR, INPUT_PULLUP);
mx.begin();
#if DEBUG
Serial.begin(57600);
#endif
PRINTS("\n[MD_MAX72XX Test & Demo]");
}
//------------------------------------------------------------------------------------------------------------------------------------
void standby()
// Demonstrate the use of buffer based repeated patterns
// across all devices.
{
PRINTS("\nBullseye");
mx.clear();
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
for (uint8_t n=0; n<3; n++)
{
byte b = 0xff;
int i = 0;
while (b != 0x00)
{
for (uint8_t j=0; j<MAX_DEVICES+1; j++)
{
mx.setRow(j, i, b);
mx.setColumn(j, i, b);
mx.setRow(j, ROW_SIZE-1-i, b);
mx.setColumn(j, COL_SIZE-1-i, b);
}
mx.update();
delay(3*DELAYTIME);
for (uint8_t j=0; j<MAX_DEVICES+1; j++)
{
mx.setRow(j, i, 0);
mx.setColumn(j, i, 0);
mx.setRow(j, ROW_SIZE-1-i, 0);
mx.setColumn(j, COL_SIZE-1-i, 0);
}
bitClear(b, i);
bitClear(b, 7-i);
i++;
}
while (b != 0xff)
{
for (uint8_t j=0; j<MAX_DEVICES+1; j++)
{
mx.setRow(j, i, b);
mx.setColumn(j, i, b);
mx.setRow(j, ROW_SIZE-1-i, b);
mx.setColumn(j, COL_SIZE-1-i, b);
}
mx.update();
delay(3*DELAYTIME);
for (uint8_t j=0; j<MAX_DEVICES+1; j++)
{
mx.setRow(j, i, 0);
mx.setColumn(j, i, 0);
mx.setRow(j, ROW_SIZE-1-i, 0);
mx.setColumn(j, COL_SIZE-1-i, 0);
}
i--;
bitSet(b, i);
bitSet(b, 7-i);
}
}
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}
//------------------------------------------------------------------------------------------------------------------------------------
void transformation1()
// Demonstrates the use of transform() to move bitmaps on the display
// In this case a user defined bitmap is created and animated.
{
uint8_t arrow[COL_SIZE] =
{
0b00001000,
0b00011100,
0b00111110,
0b01111111,
0b00011100,
0b00011100,
0b00111110,
0b00000000
};
MD_MAX72XX::transformType_t t[] =
{
MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL,
MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL,
MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL,
MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL, MD_MAX72XX::TSL,
};
PRINTS("\nTransformation1");
mx.clear();
// use the arrow bitmap
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
for (uint8_t j=0; j<mx.getDeviceCount(); j++)
mx.setBuffer(((j+1)*COL_SIZE)-1, COL_SIZE, arrow);
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
delay(DELAYTIME);
// run through the transformations
mx.control(MD_MAX72XX::WRAPAROUND, MD_MAX72XX::ON);
for (uint8_t i=0; i<(sizeof(t)/sizeof(t[0])); i++)
{
mx.transform(t[i]);
delay(DELAYTIME*4);
}
mx.control(MD_MAX72XX::WRAPAROUND, MD_MAX72XX::OFF);
}
//------------------------------------------------------------------------------------------------------------------------------------
void loop()
{
standby();
if (BUTTON_PINL == HIGH)
{
transformation1();
}
}
I am looking for your answers !