#include <FastLED.h>
#define ROTARY_DIAL_PULSE_PIN 2
#define WIDTH 16
#define HEIGHT 16
#define NUM_ROWS HEIGHT
#define NUM_COLS WIDTH
CRGB leds[266];
CRGB ledsbuff[266];
uint16_t AB(uint8_t b, uint8_t a) {
if (a >= WIDTH) return 256;
if (b >= HEIGHT) return 256;
uint16_t i;
if ( b & 0x01) {
// Odd rows run backwards
uint8_t reverseA = (16 - 1) - a;
i = (b * 16) + reverseA;
} else {
// Even rows run forwards
i = (b * 16) + a;
}
return i;
}
#define DATA_PIN 3
#define BRIGHTNESS 200
#define green_button 31
#define yellow_button 33
#define red_button 35
int green_button_state = 0;
int yellow_button_state = 0;
int red_button_state = 0;
byte active_button = 1;
#define INDIALPIN 48
#define PULSEPIN 52
boolean inDialPinLastState;
boolean pulsPinLastState;
byte counter = 0;
int LEDNUMBER = 0;
int NumColor =0;
long topLEDcolor = CRGB::Red;
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
const int buttonPin = 37; // the pin that the pushbutton is attached to
int animation_frame = 1;
int potpin = A4;
int potvalue = 0;
int sand_position =4;
long randNumber[10] = {
CRGB::Red,
CRGB::DeepPink,
CRGB::Orange,
CRGB::Yellow,
CRGB::Green,
CRGB::Aquamarine,
CRGB::Blue,
CRGB::Indigo,
CRGB::Violet,
CRGB::Purple,
};
long redcolors [6] = {
CRGB::Red,
CRGB(165, 1, 29),
CRGB::Orange,
CRGB(242, 10, 130),
CRGB::OrangeRed,
CRGB::Maroon,
};
long yellowcolors [6] = {
CRGB::Yellow,
CRGB::Goldenrod,
CRGB::Orange,
CRGB(247, 220, 11),
CRGB(180, 246, 14),
CRGB(142, 255, 4),
};
long greencolors [6] = {
CRGB::Green,
CRGB::LimeGreen,
CRGB(0, 166, 255),
CRGB(0, 29, 249),
CRGB(97, 0, 234),
CRGB(4, 255, 196),
};
byte sandspeed = 0;
int animation_interval = 0;
const long display_interval = 2000;
unsigned long current_Millis=0;
unsigned long previous_Millis=0;
uint8_t digit1[] = {130, 126, 131, 100, 125, 132, 124, 133, 123, 134, 122, 135, 121, 136, 120, 137, 119, 138, 118, 139, 117, 140, 116, 141, 115, 142, 111, 114, 143, 146};
uint8_t digit2[] = {162, 159, 130, 127, 98, 95, 190, 163, 158, 131, 126, 99, 94, 67, 196, 189, 164, 93, 68, 61, 197, 188, 69, 60, 91, 70, 59, 103, 90, 71, 121, 104, 89, 137, 120, 105, 151, 138, 119, 171, 150, 139, 181, 172, 149, 205, 180, 173, 206, 179, 174, 147, 142, 115, 110, 83, 78, 51, 207, 178, 175, 146, 143, 114, 111, 82, 79, 50};
uint8_t digit3[] = {66, 95, 98, 127, 130, 159, 162, 62, 67, 94, 99, 126, 131, 158, 163, 190, 61, 68, 164, 189, 196, 188, 197, 187, 198, 167, 186, 199, 104, 121, 136, 153, 168, 185, 105, 120, 137, 152, 169, 184, 170, 183, 202, 182, 203, 181, 204, 52, 77, 173, 180, 205, 51, 78, 83, 110, 115, 142, 147, 174, 179, 79, 82, 111, 114, 143, 146, 175};
uint8_t digit4[] = {66, 95, 162, 191, 67, 94, 163, 190, 68, 93, 164, 189, 69, 92, 165, 188, 70, 91, 166, 187, 71, 90, 167, 186, 72, 89, 104, 121, 136, 153, 168, 185, 73, 88, 105, 120, 137, 152, 169, 184, 170, 183, 171, 182, 172, 181, 173, 180, 174, 179, 175, 178};
uint8_t digit5[] = {63, 66, 95, 98, 127, 130, 159, 162, 191, 194, 62, 67, 94, 99, 126, 131, 158, 163, 190, 195, 61, 68, 60, 69, 59, 70, 58, 71, 90, 103, 122, 135, 154, 167, 57, 72, 89, 104, 121, 136, 153, 168, 185, 169, 184, 201, 183, 202, 182, 203, 181, 204, 52, 77, 173, 180, 205, 51, 78, 83, 110, 115, 142, 147, 174, 179, 79, 82, 111, 114, 143, 146, 175};
uint8_t digit6[] = {66, 95, 98, 127, 130, 159, 162, 62, 67, 94, 99, 126, 131, 158, 163, 190, 61, 68, 164, 189, 60, 69, 59, 70, 58, 71, 57, 72, 104, 121, 136, 153, 168, 56, 73, 88, 105, 120, 137, 152, 169, 184, 55, 74, 87, 170, 183, 54, 75, 171, 182, 53, 76, 172, 181, 52, 77, 173, 180, 51, 78, 83, 110, 115, 142, 147, 174, 179, 79, 82, 111, 114, 143, 146, 175};
uint8_t digit7[] = {63, 66, 95, 98, 127, 130, 159, 162, 191, 194, 62, 67, 94, 99, 126, 131, 158, 163, 190, 195, 189, 196, 188, 197, 187, 198, 167, 186, 199, 153, 168, 185, 137, 152, 169, 119, 138, 151, 107, 118, 139, 85, 108, 117, 77, 84, 109, 51, 78, 83, 50, 79};
uint8_t digit8[] = {66, 95, 98, 127, 130, 159, 162, 191, 62, 67, 94, 99, 126, 131, 158, 163, 190, 195, 61, 68, 189, 196, 60, 69, 188, 197, 59, 70, 187, 198, 58, 71, 186, 199, 72, 89, 104, 121, 136, 153, 168, 185, 73, 88, 105, 120, 137, 152, 169, 184, 55, 74, 183, 202, 54, 75, 182, 203, 53, 76, 181, 204, 52, 77, 180, 205, 51, 78, 83, 110, 115, 142, 147, 174, 179, 206, 79, 82, 111, 114, 143, 146, 175, 178};
uint8_t digit9[] = {95, 98, 127, 130, 159, 162, 67, 94, 99, 126, 131, 158, 163, 190, 61, 68, 93, 164, 189, 196, 60, 69, 188, 197, 59, 70, 187, 198, 58, 71, 90, 167, 186, 199, 72, 89, 104, 121, 136, 153, 168, 185, 200, 88, 105, 120, 137, 152, 184, 201, 183, 202, 182, 203, 53, 76, 181, 204, 52, 77, 84, 173, 180, 205, 78, 83, 110, 115, 142, 147, 174, 179, 82, 111, 114, 143, 146, 175};
uint8_t digit0[] = {63, 159, 162, 191, 194, 35, 62, 131, 158, 163, 190, 195, 222, 29, 36, 61, 125, 132, 157, 196, 221, 228, 37, 60, 124, 133, 220, 229, 38, 59, 123, 134, 219, 230, 39, 58, 122, 135, 218, 231, 40, 57, 121, 136, 217, 232, 41, 56, 120, 137, 216, 233, 42, 55, 119, 138, 215, 234, 43, 54, 118, 139, 214, 235, 44, 53, 117, 140, 213, 236, 45, 52, 116, 141, 148, 205, 212, 237, 46, 51, 142, 147, 174, 179, 206, 211, 18, 47, 50, 79, 146, 175, 178, 207};
int digit1_length = 30;
int digit2_length = 68;
int digit3_length = 68;
int digit4_length = 52;
int digit5_length = 72;
int digit6_length = 75;
int digit7_length = 52;
int digit8_length = 84;
int digit9_length = 78;
int digit0_length = 94;
//joystick settings
#define pinX A14
#define pinY A15
#define swPin 2
int snake[255]; // array of snake elements
int snakeSize = 2; // real snake size
int snakeSpeed = 200;
int row; // row number
int col; // column number
int lastDirection = 135; // start direction
int i, newDirection, OlddX = 1, OlddY, f;
int red, green, blue, fred, fgreen, fblue; //colors
int switch_1_pin = 49;
int switch_2_pin = 45;
int switch_3_pin = 51;
int switch_4_pin = 43;
int switch_5_pin = 53;
int switch_6_pin = 41;
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
const bool kMatrixSerpentineLayout = true;
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if ( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
}
if ( kMatrixSerpentineLayout == true) {
if ( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
return i;
}
const long dolly1[]PROGMEM = {
0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0x009900,0x009900,0x009900,
0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFF2CC,0xFFFFFF,0x000000,0xFFF2CC,0xFFF2CC,0xFFFFFF,0x000000,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,
0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFF2CC,0x000000,0x000000,0xFFF2CC,0xFFF2CC,0x000000,0x000000,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,
0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,
0x009900,0x009900,0x009900,0x009900,0xFFF2CC,0xFF9999,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFF9999,0xFFF2CC,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0x009900,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x000000,0xFFF2CC,0xFFF2CC,0x009900,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x002060,0x002060,0x00B0F0,0x002060,0x002060,0xC00000,0x002060,0x00B0F0,0x002060,0x002060,0x009900,0x009900,0x009900,
0x009900,0x009900,0x002060,0xC00000,0x002060,0x00B0F0,0xC00000,0x002060,0x002060,0x002060,0x00B0F0,0x002060,0xC00000,0x002060,0x009900,0x009900,
0x009900,0x002060,0x002060,0x009900,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x009900,0x002060,0x002060,0x009900
};
const long dolly2[]PROGMEM = {
0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,0x009900,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0x009900,0x009900,0x009900,
0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFF2CC,0xFFFFFF,0x000000,0xFFF2CC,0xFFF2CC,0xFFFFFF,0x000000,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,
0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFF2CC,0x000000,0x000000,0xFFF2CC,0xFFF2CC,0x000000,0x000000,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,
0x009900,0xFFFF00,0xFFFF00,0xFFFF00,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFFF00,0xFFFF00,0xFFFF00,0x009900,
0x009900,0x009900,0x009900,0x009900,0xFFF2CC,0xFF9999,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFF9999,0xFFF2CC,0x009900,0x009900,0x009900,0x009900,
0xFFF2CC,0x002060,0x009900,0x009900,0x009900,0xFFF2CC,0xFFF2CC,0x000000,0x000000,0xFFF2CC,0xFFF2CC,0x009900,0x009900,0x009900,0x002060,0xFFF2CC,
0xFFF2CC,0x002060,0x002060,0x002060,0x009900,0x009900,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x009900,0x009900,0x002060,0x002060,0x002060,0xFFF2CC,
0x009900,0x009900,0x002060,0x002060,0x002060,0x00B0F0,0x002060,0x002060,0xC00000,0x002060,0x00B0F0,0x002060,0x002060,0x002060,0x009900,0x009900,
0x009900,0x009900,0x009900,0xC00000,0x002060,0x00B0F0,0xC00000,0x002060,0x002060,0x002060,0x00B0F0,0x002060,0xC00000,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x009900,0x009900,0x009900,0x009900,
0x009900,0x009900,0x009900,0x009900,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x009900,0x009900,0x009900,0x009900
};
const long pebbles1[]PROGMEM = {
0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0x00B0F0,
0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x00B0F0,0x00B0F0,0xFF9900,0x833C0C,0x833C0C,0x833C0C,0xFF9900,0x00B0F0,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x00B0F0,0x833C0C,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0x833C0C,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x833C0C,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0x833C0C,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0x00B0F0,
0x00B0F0,0x833C0C,0x000000,0xFFFFFF,0xFFFF00,0xFFFF00,0xFFFF00,0x000000,0xFFFFFF,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0xFFFF00,0x00B0F0,0x00B0F0,
0x00B0F0,0x833C0C,0xFFFFFF,0xFFFFFF,0xFF9900,0xFF9900,0xFF9900,0xFFFFFF,0xFFFFFF,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0x00B0F0,0x833C0C,0x70AD47,0x70AD47,0x70AD47,0x833C0C,0x70AD47,0x70AD47,0x70AD47,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0x00B0F0,0x833C0C,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0x00B0F0,0x833C0C,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x000000,0xFFF2CC,0xFFF2CC,0x833C0C,0x00B0F0,0x00B0F0,0x833C0C,0x833C0C,0x00B0F0,0x00B0F0,
0x00B0F0,0x00B0F0,0x833C0C,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x833C0C,0x00B0F0,0x00B0F0,0xFF9900,0x833C0C,0x833C0C,0x00B0F0,0x00B0F0,
0xC00000,0x00B0F0,0x00B0F0,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x00B0F0,0xFFFF00,0xC00000,0xFF9900,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0xC00000,0xFFFF00,0x70AD47,0xFF9900,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFF9900,0x70AD47,0xFFFF00,0xC00000,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0x00B0F0,0xFFFF00,0x70AD47,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0x70AD47,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,
0x00B0F0,0x00B0F0,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0
};
const long pebbles2[]PROGMEM = {
0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,
0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,
0x00B0F0,0x00B0F0,0x00B0F0,0xFF9900,0x833C0C,0x833C0C,0x833C0C,0xFF9900,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0x00B0F0,
0x00B0F0,0x00B0F0,0x833C0C,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0x833C0C,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x833C0C,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0x833C0C,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x833C0C,0xFFFFFF,0x000000,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFFFF,0x000000,0x833C0C,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x833C0C,0xFFFFFF,0xFFFFFF,0xFF9900,0xFF9900,0xFF9900,0xFFFFFF,0xFFFFFF,0x833C0C,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,0xFFFF00,
0x00B0F0,0x833C0C,0x70AD47,0x70AD47,0x70AD47,0x833C0C,0x70AD47,0x70AD47,0x70AD47,0x833C0C,0x00B0F0,0x00B0F0,0xFFFF00,0xFFFF00,0xFFFF00,0x00B0F0,
0x00B0F0,0x833C0C,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0xFFFF00,0x00B0F0,0x00B0F0,
0x00B0F0,0x833C0C,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x000000,0x000000,0xFFF2CC,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0x00B0F0,0x00B0F0,0x833C0C,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFFF2CC,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0x00B0F0,0x00B0F0,0x00B0F0,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x00B0F0,0xFFFF00,0xC00000,0xFF9900,0x833C0C,0x833C0C,0x00B0F0,0x00B0F0,
0x00B0F0,0xFFFF00,0x70AD47,0xFF9900,0xFFF2CC,0xFFF2CC,0xFFF2CC,0xFF9900,0x70AD47,0xFFFF00,0xC00000,0xFF9900,0x833C0C,0x833C0C,0x00B0F0,0x00B0F0,
0xC00000,0xFFFF00,0x70AD47,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0xFF9900,0x70AD47,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0xC00000,0x00B0F0,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0xC00000,0x00B0F0,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,
0x00B0F0,0x00B0F0,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x833C0C,0x00B0F0,0x00B0F0,0x00B0F0,0x000000,0x00B0F0,0x00B0F0,0x00B0F0
};
const long kitty1[]PROGMEM = {
0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0X00B0F0,0X00B0F0,
0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0X000000,0X00B0F0,
0X00B0F0,0X000000,0X000000,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XFF9999,0XBFBFBF,0X000000,0X000000,0XBFBFBF,0XFF9999,0XBFBFBF,0X000000,
0X000000,0X757171,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,
0X000000,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X000000,0X757171,0X000000,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X000000,0XBFBFBF,0X757171,0X000000,0X000000,0X000000,0XBFBFBF,0XBFBFBF,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,0XBFBFBF,0XBFBFBF,
0X00B0F0,0X000000,0XBFBFBF,0X757171,0XBFBFBF,0X757171,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XFF9999,0XFFFFFF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X00B0F0,0X000000,0XBFBFBF,0X757171,0XBFBFBF,0X757171,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,
0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,0X00B0F0,
0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XBFBFBF,0XBFBFBF,0X000000,0X00B0F0,
0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XBFBFBF,0XFFFFFF,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,
0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0X000000,0XBFBFBF,0XBFBFBF,0X000000,0X000000,0XBFBFBF,0X000000,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,
0X00B0F0,0X00B0F0,0X000000,0XFFFFFF,0X000000,0X000000,0XFFFFFF,0X000000,0X00B0F0,0X000000,0XFFFFFF,0X000000,0XFFFFFF,0X000000,0X00B0F0,0X00B0F0,
0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900
};
const long kitty2[]PROGMEM = {
0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,
0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0X00B0F0,0X00B0F0,
0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0X000000,0X00B0F0,
0X000000,0X000000,0X00B0F0,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XFF9999,0XBFBFBF,0X000000,0X000000,0XBFBFBF,0XFF9999,0XBFBFBF,0X000000,
0XBFBFBF,0X757171,0X000000,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,
0X000000,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X000000,0X757171,0X000000,0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X000000,0XBFBFBF,0XBFBFBF,0X000000,0X000000,0X000000,0XBFBFBF,0XBFBFBF,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,0XBFBFBF,0XBFBFBF,
0X00B0F0,0X000000,0XBFBFBF,0X757171,0XBFBFBF,0X757171,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XFF9999,0XFFFFFF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X00B0F0,0X000000,0XBFBFBF,0X757171,0XBFBFBF,0X757171,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,
0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,
0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0X000000,0X00B0F0,
0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XBFBFBF,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XBFBFBF,0XBFBFBF,0X000000,0X00B0F0,
0X00B0F0,0X00B0F0,0X000000,0XBFBFBF,0XBFBFBF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XFFFFFF,0XBFBFBF,0XFFFFFF,0XBFBFBF,0X000000,0X00B0F0,0X00B0F0,
0X00B0F0,0X00B0F0,0X000000,0XFFFFFF,0X000000,0X000000,0XFFFFFF,0X000000,0X00B0F0,0X000000,0XFFFFFF,0X000000,0XFFFFFF,0X000000,0X00B0F0,0X00B0F0,
0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900,0X009900
};
void setup() {
Serial.begin(115200);
Serial.println("System started");
randomSeed(analogRead(0));
pinMode(INDIALPIN, INPUT_PULLUP);
pinMode(PULSEPIN, INPUT_PULLUP);
inDialPinLastState = digitalRead(INDIALPIN);
pulsPinLastState = digitalRead(PULSEPIN);
pinMode (switch_1_pin, INPUT);
pinMode (switch_2_pin, INPUT);
pinMode (switch_3_pin, INPUT);
pinMode (switch_4_pin, INPUT);
pinMode (switch_5_pin, INPUT);
pinMode (switch_6_pin, INPUT);
pinMode (green_button, INPUT);
pinMode (yellow_button, INPUT);
pinMode (red_button, INPUT);
pinMode(buttonPin, INPUT);
red = random(0, 255);
green = random(0, 255);
blue = random(0, 255);
fred = random(127, 255);
fgreen = random(127, 255);
fblue = random(127, 255);
pinMode(pinX, INPUT);
pinMode(pinY, INPUT);
pinMode(swPin, INPUT);
digitalWrite(swPin, HIGH);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, 266);
FastLED.setBrightness(BRIGHTNESS);
for( i=0; i<=255; i++ ){
snake[i] = 0;
unsigned long lastdigit = 0;
int newline = true;
}
for( i=0; i<=snakeSize; i++ ){
snake[i] = lastDirection+i;
}
f = random(0, 255);
FastLED.show();
}
unsigned long lastdigit = 0;
int newline = true;
void loop() {
if(millis()<100){
for( i=256; i < 266; i++) {
leds[i] = CRGB::Green;
FastLED.show();
delay(100);
}
delay (500);
for( i=265; i >= 256; i-- ) {
leds[i] = CRGB::Black;
FastLED.show();
delay(100);
}
}
potvalue = analogRead(potpin);
animation_interval = map(potvalue, 0, 1023, 800, 125);
sandspeed = map(potvalue, 0, 1020, 10, 150);
sand_position = map(analogRead(A14), 0, 1023, 1,14);
if(switch_1_pin == LOW && switch_2_pin == LOW && switch_3_pin == LOW && switch_4_pin == LOW && switch_5_pin == LOW && switch_6_pin == LOW )
{}// put code here for the 7th position
if(digitalRead(switch_1_pin) ==HIGH){animation();
}
if(digitalRead(switch_2_pin) == HIGH){
}
if(digitalRead(switch_3_pin) == HIGH){
}
if(digitalRead(switch_4_pin) == HIGH){snake_game();
}
if(digitalRead(switch_5_pin) == HIGH){dial_number();
}
if(digitalRead(switch_6_pin) == HIGH){sand();
}
green_button_state = digitalRead(green_button);
yellow_button_state = digitalRead(yellow_button);
red_button_state = digitalRead(red_button);
if(green_button_state == HIGH){active_button=1;}
if(yellow_button_state == HIGH){active_button=2;}
if(red_button_state == HIGH){active_button=3;}
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
}
}
lastButtonState = buttonState;
if (buttonPushCounter > 10) { buttonPushCounter=0;
for( i=256; i < (10+256); i++) {
leds[i] = CRGB::Black;
FastLED.show();
topLEDcolor=randNumber[random(1,8)];
}
}
for( i=256; i < (buttonPushCounter+256); i++) {
leds[i] = topLEDcolor;
}
FastLED.show();
}
void snake_game() {
color( digitalRead(swPin) );
newDirection = Snakedirection(lastDirection, analogRead(pinX), analogRead(pinY));
lastDirection = snakeMove(newDirection);
food(newDirection);
delay(snakeSpeed);
}
int Snakedirection(int last, int dX, int dY ){
dX = map(dX, 0, 1000, 1, -1);
dY = map(dY, 0, 1000, -1, 1);
if(dX == 0 && dY == 0 && OlddX != dX){
dX = OlddX;
}
if(dY == 0 && dX == 0 && OlddY != dY){
dY = OlddY;
}
int newDirection = last;
if( dX != 0 ){ // moving in X direction
if ( row&1 ){
if( col == 0 && dX == 1){ newDirection = last -15; }
else if( col == 15 && dX == -1){ newDirection = last +15; }
else newDirection = last + dX; // четная
} else {
if( col == 0 && dX == 1){ newDirection = last +15; }
else if( col == 15 && dX == -1 ){ newDirection = last -15; }
else newDirection = last - dX; // не четная
}
}
if( dY < 0){ // moving in Y DOWN direction
if(row == 15 && dY == -1){newDirection = col;}
else if ( row&1 ){
newDirection = last + (col*2)+1; // четная
} else {
newDirection = last + (16-col-1)+(16-col); // не четная
}
}
if( dY > 0){ // moving in Y UP direction
if( row == 0 && dY == 1){ newDirection = 255 - col;}
else if ( row&1 ){
newDirection = last - (last - 16*row) - (16 - col); // четная
} else {
newDirection = last - (col*2)-1; // не четная
}
}
OlddX = dX;
OlddY = dY;
return newDirection;
}
int snakeMove(int snakeDirection){
for( i=0; i<=255; i++ ){
if( snake[i] == snakeDirection ){
death();
}
}
FastLED.clear();
for(i=snakeSize; i>=1; i--){
snake[i] = snake[i-1];
}
snake[0] = snakeDirection;
for( i=0; i<=255; i++ ){
if( snake[i] ){
leds[snake[i]].setRGB(red, green, blue);
}
}
FastLED.show();
row = (int)(snakeDirection/16); // row number
if ( row&1 ){
col = (row+1) * 16 - snakeDirection - 1;
} else {
col = snakeDirection - row * 16;
}
return snakeDirection;
}
void food( int eaten ){
if( eaten == f ){
snakeSize++;
f = random(0, 255);
red = fred;
green = fgreen;
blue = fblue;
fred = random(0, 255);
fgreen = random(0, 255);
fblue = random(0, 255);
snakeSpeed = snakeSpeed / 1.1;
} else {
leds[f].setRGB(fred, fgreen, fblue);
FastLED.show();
}
}
void death(){
snakeSize = 2;
snakeSpeed = 500;
red = 255;
green = 0;
blue = 0;
}
void color(boolean sw){
if(!sw){
red = random(0,255);
green = random(0,255);
blue = random(0,255);
}
}
void animation (){
if (active_button == 1){pebbles_animation();}
if (active_button == 2){ dolly_animation();}
if (active_button == 3){kitty_animation();}
}
void pebbles_animation() {
unsigned long current_Millis = millis();
if(current_Millis - previous_Millis > animation_interval) {
previous_Millis=current_Millis;
if (animation_frame == 1) {
animation_frame = 2;
} else {animation_frame = 1;
}
}
if(animation_frame == 1) {
drawpebbles1();
}
else {drawpebbles2();}
}
void drawpebbles1() {
int counter = 0;
for (int i = 0; i < kMatrixWidth; i++) {
for (int j = 0; j < kMatrixHeight; j++) {
leds[XY(i, j)] = pgm_read_dword(&pebbles1[counter]);
counter++;
}
}
LEDS.show();
}
void drawpebbles2() {
int counter = 0;
for (int i = 0; i < kMatrixWidth; i++) {
for (int j = 0; j < kMatrixHeight; j++) {
leds[XY(i, j)] = pgm_read_dword(&pebbles2[counter]);
counter++;
}
}
LEDS.show();
}
void dolly_animation() {
unsigned long current_Millis = millis();
if(current_Millis - previous_Millis > animation_interval) {
previous_Millis=current_Millis;
if (animation_frame == 1) {
animation_frame = 2;
} else {animation_frame = 1;
}
}
if(animation_frame == 1) {
drawdolly1();
}
else {drawdolly2();
}
}
void drawdolly1() {
int counter = 0;
for (int i = 0; i < kMatrixWidth; i++) {
for (int j = 0; j < kMatrixHeight; j++) {
leds[XY(i, j)] = pgm_read_dword(&dolly1[counter]);
counter++;
}
}
LEDS.show();
}
void drawdolly2() {
int counter = 0;
for (int i = 0; i < kMatrixWidth; i++) {
for (int j = 0; j < kMatrixHeight; j++) {
leds[XY(i, j)] = pgm_read_dword(&dolly2[counter]);
counter++;
}
}
LEDS.show();
}
void kitty_animation() {
unsigned long current_Millis = millis();
if(current_Millis - previous_Millis > animation_interval) {
previous_Millis=current_Millis;
if (animation_frame == 1) {
animation_frame = 2;
} else {animation_frame = 1;
}
}
if(animation_frame == 1) {
drawkitty1();
}
else {drawkitty2();
}
}
void drawkitty1() {
int counter = 0;
for (int i = 0; i < kMatrixWidth; i++) {
for (int j = 0; j < kMatrixHeight; j++) {
leds[XY(i, j)] = pgm_read_dword(&kitty1[counter]);
counter++;
}
}
LEDS.show();
}
void drawkitty2() {
int counter = 0;
for (int i = 0; i < kMatrixWidth; i++) {
for (int j = 0; j < kMatrixHeight; j++) {
leds[XY(i, j)] = pgm_read_dword(&kitty2[counter]);
counter++;
}
}
LEDS.show();
}
void dial_number() {
boolean inDialPinState = digitalRead(INDIALPIN);
boolean pulsPinState = digitalRead(PULSEPIN);
if (inDialPinState != inDialPinLastState) {
if (!inDialPinState) {
Serial.println("Start of dial");
counter = 0;
} else {
Serial.println("End of dial");
Serial.print("Dialed Digit - ");
Serial.println(counter);
NumColor = randNumber[random(1,8)];
LEDNUMBER = counter;
FastLED.clear();
previous_Millis= millis();
shownumbers();
}
}
inDialPinLastState = inDialPinState;
if (pulsPinLastState != pulsPinState) {
if (!pulsPinLastState) {
counter++;
}
Serial.println("pulsPinState - " + String(pulsPinState));
pulsPinLastState = pulsPinState;
}
unsigned long current_Millis = millis();
if(current_Millis - previous_Millis > display_interval) {
previous_Millis =current_Millis;
FastLED.clear();
LEDS.show();
}
}
void shownumbers() {
if (LEDNUMBER == 1) {
for (uint16_t i = 0; i < (digit1_length) ; i++) {
leds[digit1[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 2) {
for (uint16_t i = 0; i < (digit2_length) ; i++) {
leds[digit2[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 3) {
for (uint16_t i = 0; i < (digit3_length) ; i++) {
leds[digit3[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 4) {
for (uint16_t i = 0; i < (digit4_length) ; i++) {
leds[digit4[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 5) {
for (uint16_t i = 0; i < (digit5_length) ; i++) {
leds[digit5[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 6) {
for (uint16_t i = 0; i < (digit6_length) ; i++) {
leds[digit6[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 7) {
for (uint16_t i = 0; i < (digit7_length) ; i++) {
leds[digit7[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 8) {
for (uint16_t i = 0; i < (digit8_length) ; i++) {
leds[digit8[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 9) {
for (uint16_t i = 0; i < (digit9_length) ; i++) {
leds[digit9[i] - 1] = NumColor;
}
}
if (LEDNUMBER == 10) {
for (uint16_t i = 0; i < (digit0_length) ; i++) {
leds[digit0[i] - 1] = NumColor;
}
}
LEDS.show();
}
void sand(){
SandMachine();
FastLED.show();
}
void SandMachine(){
sandspeed = map(potvalue, 0, 1020, 1, 150);
EVERY_N_MILLISECONDS_I(thistimer,0) {thistimer.setPeriod(sandspeed);updatesand(); randomdot();countSand();} //speed of sand effect
memcpy8(leds, ledsbuff, 256*3);
Serial.println(sandspeed);
}
void randomdot(){
#define randomdothue rand() //This value changes the color range Should map this to the potentiometer for color changing effect
byte a= sand_position;
if (active_button == 1){if (!random8(4)) ledsbuff[AB(a,0)].setHue(random8(80, 170));
}
if (active_button == 2){if (!random8(4)) ledsbuff[AB(a,0)].setHue(random8(40, 85));
}
if (active_button == 3){if (!random8(4)) ledsbuff[AB(a,0)].setHue(random8(0, 40));
//
}
}
void updatesand (){
int index, indexAadd1B, indexAsub1B, indexABadd1;
for (int b=NUM_ROWS-1; b>0; b--) {
for (int a=1; a<NUM_COLS-1; a++) {
index = AB(a,b); indexAadd1B = AB(a+1,b); indexAsub1B = AB(a-1,b); indexABadd1 = AB(a,b-1);
if (!ledsbuff[index] && !ledsbuff[indexABadd1]) continue;
if (!ledsbuff[index] && ledsbuff[indexABadd1]) {ledsbuff[index]=ledsbuff[indexABadd1]; ledsbuff[indexABadd1]=0;}
if (ledsbuff[index] && ledsbuff[indexABadd1] && !ledsbuff[indexAsub1B] && !ledsbuff[indexAadd1B])
if (random8(2)) {ledsbuff[indexAsub1B]=ledsbuff[indexABadd1]; ledsbuff[indexABadd1]=0;}
else {ledsbuff[indexAadd1B]=ledsbuff[indexABadd1]; ledsbuff[indexABadd1]=0;}
if (ledsbuff[index] && ledsbuff[indexABadd1] && !ledsbuff[indexAsub1B] && ledsbuff[indexAadd1B]) {ledsbuff[indexAsub1B]=ledsbuff[indexABadd1]; ledsbuff[indexABadd1]=0;}
if (ledsbuff[index] && ledsbuff[indexABadd1] && ledsbuff[indexAsub1B] && !ledsbuff[indexAadd1B]) {ledsbuff[indexAadd1B]=ledsbuff[indexABadd1]; ledsbuff[indexABadd1]=0;}
}
}
}
void randomdel(){
for (int i=0; i< 256; i++) {
if (!random8(3)) ledsbuff[i]=0;
}
}
void falldown(){
int indexABsub1, index;
for (int b=NUM_ROWS-1; b>0; b--) {
for (int a=0; a<NUM_COLS; a++) {
indexABsub1 =AB(a,b-1); index= AB(a,b);
if (!ledsbuff[index] && ledsbuff[indexABsub1]) {ledsbuff[index]=ledsbuff[indexABsub1]; ledsbuff[indexABsub1]=0;}
}
}
}
void countSand() {
uint16_t totalSand = 0;
byte rand = random8(30);
for (uint16_t i = 0; i < 256; i++) {
if (ledsbuff[i]) {
totalSand++;
if (totalSand >= 256 / 3 + rand ) {randomdel(); falldown(); falldown(); falldown(); break;} //N_leds/3 this how many sands on screen? maybe time to delete some?
}
}
}