#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
//#include <LiquidCrystal_I2C.h>
// OCTOBER
#define VERSION " QDrum_Screen v0.4"
#define TEST_BUTTON
//#define LOG_ON
#ifdef TEST_BUTTON
#define PIN_TEST_BUTTON 13
#define PIN_TEST_SIGNAL 4
#define LENGHT_TEST_SIGNAL 10
bool isButtonWasPressed = false;
#endif
// PIN SET
#define PIN_SCREEN_MATRIX 3
#define PIN_INPUT_TO_PLAY 2
// SIGNAL SET
#define LENGHT_SIGNAL_TO_PLAY 5 //ms
// SCREEN SIZE
#define X_SIZE 13
#define Y_SIZE 29
#define DEFAULT_TYPE_ANIMATION 1 //
#define FPS_ANIMATION 30
#define K_SMOOTH 0.85
#define LENGHT_ANIMATION 2000
// ANIMATOIN FRAME
// ANIMATION 1 FRAME AMBIENT
#define AMBIENT_DELAY 50
#define AMBIENT_DELAY_FAST 20
#define AMBIENT_SPEED 1 // max 100!
#define AMBIENT_SPEED_FAST 5 // max 100!
uint8_t framesColorMatrix[][3]={
//R G B
//Frame ambient 1 center:
{255, 0, 0},
//Frame ambient 1 frame:
{255, 255, 255},
//Frame ambient 1 fast center:
{0, 0, 255},
//Frame ambient 1 fast frame:
{255, 255, 255},
//Frame ambient 2 center:
{255, 255, 255},
//Frame ambient 2 frame:
{255, 255, 255},
//Frame ambient 2 fast center:
{0, 255, 0},
//Frame ambient 2 fast frame:
{255, 255, 255},
//Frame 3 center:
{255, 255, 255},
//Frame 3 frame:
{255, 255, 255},
//Frame 4 center:
{0, 255, 0},
//Frame 4 frame:
{255, 0, 0},
//Frame 5 center:
{255, 255, 255},
//Frame 5 frame:
{255, 255, 255}
};
uint8_t flagsColorMatrix[][3]={
//R G B
//2 Flag 1 RUS
{255, 255, 255}, //white
{0 , 0 , 255}, //blue
{255, 0 , 0 }, //red
//3 Flag 2 RUS upside-down
{255, 0 , 0 }, //red
{0 , 0 , 255}, //blue
{255, 255, 255}, //white
//4 Flag 3
{255, 0 , 0. },
{0 , 255, 0 },
{255, 0 , 0 },
//5 Flag 4
{0 , 0 , 255},
{0 , 255, 0 },
{255, 0 , 0 },
//6 Flag 5
{0 , 0 , 255},
{0 , 255, 0 },
{0 , 0 , 255},
//7 Flag 6
{0 , 0 , 255},
{255, 255, 255},
{0 , 0 , 255},
};
struct Color
{
uint8_t r;
uint8_t g;
uint8_t b;
};
enum TypeAnimation
{
FRAME_AMBIENT_ROTATE,
FRAME_AMBIENT_ROTATE_FAST,
FRAME_AMBIENT_WHOLE,
FRAME_AMBIENT_WHOLE_FAST,
FRAME,
FLAG,
NOTHING
};
//ANIMATION FRAME GLOBAL
#define FIRST_FRAME_NUMBER_ANIMATION 1
#define COUNT_OF_FRAMES 7
Color colorFrame;
Color colorFrameCenter;
uint8_t frameColor = 0;
bool isFrameColorPlus = true;
uint64_t timerAmbient = millis();
//ANIMATION FLAG GLOBAL
#define FIRST_FLAG_NUMBER_ANIMATION 8
#define COUNT_OF_FLAGS 6
Color colorsFlag[3];
//SCREEN CONFIG
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(X_SIZE, Y_SIZE, PIN_SCREEN_MATRIX,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_RGB + NEO_KHZ800);
uint8_t typeAnimation = DEFAULT_TYPE_ANIMATION; // 1-Frame; 2-Flag3
struct ScreenConfig {
uint8_t typeAnimation;
};
ScreenConfig screenConfig;
//LISTNER
uint8_t conditionOfAnimation = 0; // 0 - stop; 1 - start; 2 - continue
//Timers
uint64_t timerCheckSignal = millis();
uint64_t timerAnimationLenght = timerCheckSignal;
uint64_t timerAnimationFPS = timerCheckSignal;
uint64_t timerTestSignal = timerCheckSignal;
uint64_t timerSerialRead = timerCheckSignal;
//LCD
// LiquidCrystal_I2C lcd(0x27, 16, 4);
void setup()
{
Serial.begin(9600);
pinMode(PIN_INPUT_TO_PLAY, INPUT);
animationInitialisation();
#ifdef TEST_BUTTON
pinMode(PIN_TEST_BUTTON, INPUT);
pinMode(PIN_TEST_SIGNAL, OUTPUT);
#endif
}
void loop()
{
#ifdef TEST_BUTTON
buttonListner();
#endif
if ( (millis() - timerSerialRead) > 1000){
Serial.println("read start");
timerSerialRead = millis();
if(Serial.available())
{
if (Serial.readBytes((byte*)&screenConfig, sizeof(screenConfig)))
{
typeAnimation = screenConfig.typeAnimation;
}
}
}
listner();
loopAnimation();
}