Часы на светодиодах WS2812b

ed2022
Offline
Зарегистрирован: 09.04.2022

Здравствуйте. Такая проблема. Собрал часы на светодиодах общее кол-во 155 ( хотя это не важно). Получилась матрица размером 7x17, т.е. одна ее часть приходится на часы 7x8, другая половина 7x8 на минуты(по середине двоеточие). Забил номера светодиодов в глобальный массив const byte, чтобы изменять соответственно цифры.

#define k 7
#define l 17

const byte _hhmm[k][l] = {
// 0  1   2   3   4   5   6   7   8   9    10   11   12   13   14   15   16
// h0 h1  h2  h3  h4  h5  h6  h7
 
  {6, 8,  23, 26, 44, 59, 62, 76, 0,  94,  93,  92,  91,  89,  88,  87,  86},
  {5, 0,  0,  27, 45, 0,  0,  75, 0,  95,  0,   0,   98,  100, 0,   0,   103},
  {4, 0,  0,  28, 46, 0,  0,  74, 78, 112, 0,   0,   109, 107, 0,   0,   104},
  {3, 11, 20, 29, 47, 56, 65, 73, 0,  113, 114, 115, 116, 118, 119, 120, 121},
  {2, 0,  0,  30, 48, 0,  0,  72, 77, 130, 0,   0,   127, 125, 0,   0,   122},
  {1, 0,  0,  31, 49, 0,  0,  71, 0,  131, 0,   0,   134, 136, 0,   0,   139},
  {0, 14, 17, 32, 50, 53, 68, 70, 0,  148, 147, 146, 145, 143, 142, 141, 140},  
};

Затем создал функции для чисел от 0 до 9 по принципу:

uint32_t time_color = pixels_1.Color(255,255,255);
uint32_t black = pixels_1.Color(0,0,0);

//цифра ноль

void my_1() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);   
   }

Далее цифры один (void my_2()),

Два (void my_3()),

Три (void my_4()),

итд.

void setup() {


// стандартный код инициализации светодиодов и модуля времени DS3231

}

void loop() {

    byte h = t.hour();
    byte m = t.minute();

// цифра ноль для (ЧАСЫ)

if (h == 0 | h == 10 | h == 20){     
     my_1();         
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
// цифра один

if (h == 1 | h == 11 | h == 21){      
     my_2();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }

Итд.

Отдельно десятки (h>=10 & h<20) и двадцатки (h>=20 & h<25)

Далее тоже самое с минутами.

// цифра ноль (минуты)
if (m == 0 | m == 10 | m == 20 | m == 30 | m == 40 | m == 50) {
     my_1();
     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
                  
    }

Итд.

Но проблема в том, что когда, например, в модуле время 23:54, то цифры перемешиваются между собой и время высвечивается как 52:43 или по др. В чем проблема, как правильно? Я самоучка, прошу не судить строго

 

Komandir
Komandir аватар
Offline
Зарегистрирован: 18.08.2018

155-7*8-7*8=43 Это что за двоеточие такое ???

1. Вставьте весь код.

2. Нарисуйте как у вас соединены сегменты. (Сначала змейка шла по вертикали, потом по горизонтали ???)

То что вы уже выложили - это филькина грамота !!!

Зачем вы для каждого пикселя вызываете pixels_1.setBrightness(b); и pixels_1.show(); ??? Их надо вызывать ОДИН РАЗ после задания цвета для всех пикселей "одного кадра" !!!

ed2022
Offline
Зарегистрирован: 09.04.2022
#include <Adafruit_NeoPixel.h>
#include <RTClib.h>
#define k 7
#define l 17

byte q = 155;
byte pin_9 = 9;
int _PWDC = 0;

bool en_151307670_2;
bool en_151307670_3;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
byte b;
byte h1,h2,h3,h4;

RTC_DS3231 rtc;
DateTime t;
Adafruit_NeoPixel pixels_1 = Adafruit_NeoPixel(q, pin_9, NEO_GRB + NEO_KHZ800);


uint32_t time_color = pixels_1.Color(255,255,255);
uint32_t black = pixels_1.Color(0,0,0);

const byte _hhmm[k][l] = {
// 0  1   2   3   4   5   6   7   8   9    10   11   12   13   14   15   16
// h0 h1  h2  h3  h4  h5  h6  h7
 
  {6, 8,  23, 26, 44, 59, 62, 76, 0,  94,  93,  92,  91,  89,  88,  87,  86},
  {5, 0,  0,  27, 45, 0,  0,  75, 0,  95,  0,   0,   98,  100, 0,   0,   103},
  {4, 0,  0,  28, 46, 0,  0,  74, 78, 112, 0,   0,   109, 107, 0,   0,   104},
  {3, 11, 20, 29, 47, 56, 65, 73, 0,  113, 114, 115, 116, 118, 119, 120, 121},
  {2, 0,  0,  30, 48, 0,  0,  72, 77, 130, 0,   0,   127, 125, 0,   0,   122},
  {1, 0,  0,  31, 49, 0,  0,  71, 0,  131, 0,   0,   134, 136, 0,   0,   139},
  {0, 14, 17, 32, 50, 53, 68, 70, 0,  148, 147, 146, 145, 143, 142, 141, 140},  
};


void my_0() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);   
   }
   
//0h
void my_1() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);   
   }

//1h
void my_2() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[1][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[2][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[4][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[5][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[0][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[3][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[6][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[0][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[3][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[6][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[3][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[6][h4], time_color);   
   }

//2h
void my_3() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);   
   }   

//3h
 void my_4() {
    pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);
   }
   
//4h
void my_5(){
 pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);  
}

void my_6(){
 pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);
}

//6h
void my_7(){
 pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);
}

//7h
void my_8(){
 pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);
}

//8h
void my_9(){
 pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);
}

void my_10(){
 pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h1], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.show();   
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h4], black);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[6][h4], black);   

}

void my_11() {
  pixels_1.setBrightness(b);
   pixels_1.setPixelColor(77, time_color);
   pixels_1.show();
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(78, time_color);
   pixels_1.show();
   }

void my_12()
{
    
    if (!(0)) 
    {
         if (! _gen2I) 
        {
            _gen2I = 1;
            _gen2O = 1;
            _gen2P = millis();
        }
    }
     else 
    {
        _gen2I = 0 ;
        _gen2O= 0;
    }
    if (_gen2I) 
    {
          if (_isTimer (_gen2P , 250)) 
        {
             _gen2P = millis();
            _gen2O = ! _gen2O;
        }
    }
    en_151307670_2 = _gen2O;   
    if (en_151307670_2   == 1)
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(77, time_color);
        pixels_1.show();
    }
    else
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(77, black);
        pixels_1.show();
    }
    ;
    en_151307670_3 = _gen2O;  
    if (en_151307670_3   == 1)
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(78, time_color);
        pixels_1.show();
    }
    else
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(78, black);
        pixels_1.show();
    }
    ;
}
bool _isTimer(unsigned long startTime, unsigned long period)
{
    unsigned long currentTime;
    currentTime = millis();
    if (currentTime>= startTime) 
    {
        return (currentTime>=(startTime + period));
    }
     else 
    {
        return (currentTime >=(4294967295-startTime+period));
    }
}

void my_13() {
    _PWDC = 0;
    
}
ISR(TIMER2_OVF_vect)
{
    TCNT2=100;
    if(_PWDC >= 500)
    {
        asm volatile ("jmp 0x0000");
    }
    else
    {
        _PWDC = _PWDC+1;
    }
    ;
}
       

void setup() {
  rtc.begin();
  pixels_1.begin();  
   TCCR2A = 0x00;
   TCCR2B =  0x07;
   TIMSK2=0x01;
   TCNT2=100;

}

void loop() {
    byte h = t.hour();
    byte m = t.minute();
    my_13();
    t=rtc.now();

   
switch (analogRead(A1))
{
  case 0 ... 199:   
  b = 1; 
  my_11();
  break;
  case 200 ... 499:    
  b = 10;  
  my_12();
  break;
  case 500 ... 849:    
  b = 20;  
  my_12();
  break;
  case 850 ... 979:
  b =30;
  my_12();
  break;
 case 980 ... 1180:
  b = 50;  
  my_12();
  break;
}

    if (h == 0 | h == 10 | h == 20){     
     my_1();         
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 1 | h == 11 | h == 21){      
     my_2();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 2 | h == 12 | h == 22){      
     my_3();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 3 | h == 13 | h == 23){
     my_4();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 4 | h == 14){      
     my_5();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 5 | h == 15){     
     my_6();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 6 | h == 16){      
     my_7();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 7 | h == 17){      
     my_8();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 8 | h == 18) {     
     my_9();
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
    }
    if (h == 9 | h == 19){
     my_10();
     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
     
    }
    if (h >= 0 & h < 10){
     my_0(); 
     h1 = 0;
     h2 = 1;
     h3 = 2;
     h4 = 3;  
    }
    if (h >= 10 & h < 20){
     my_2();
     h1 = 0;
     h2 = 1;
     h3 = 2;
     h4 = 3;     
    }  
    if (h >= 20 & h < 25){
     my_3();
     h1 = 0;
     h2 = 1;
     h3 = 2;
     h4 = 3;         
    }   
    
    if (m == 0 | m == 10 | m == 20 | m == 30 | m == 40 | m == 50) {
     my_1();
     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
                  
    }
    if (m == 1 | m == 11 | m == 21 | m == 31 | m == 41 | m == 51) {
     my_2();
     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;        
    }
    if (m == 2 | m == 12 | m == 22 | m == 32 | m == 42 | m == 52) {
     my_3();
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;   
    }
    if (m == 3 | m == 13 | m == 23 | m == 33 | m == 43 | m == 53) {
     my_4();
     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;  
    }
    if (m == 4 | m == 14 | m == 24 | m == 34 | m == 44 | m == 54) {
     my_5();
         
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;          
    }
    if (m == 5 | m == 15 | m == 25 | m == 35 | m == 45 | m == 55) {
     my_6();
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;  
    }
    if (m == 6 | m == 16 | m == 26 | m == 36 | m == 46 | m == 56) {
     my_7();
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;  
    }
    if (m == 7 | m == 17 | m == 27 | m == 37 | m == 47 | m == 57) {
     my_8();
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12; 
    }
    if (m == 8 | m == 18 | m == 28 | m == 38 | m == 48 | m == 58) {
     my_9();
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12; 
    }
    if (m == 9 | m == 19 | m == 29 | m == 39 | m == 49 | m == 59) {
     my_10();
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;      
    }
    if (m >= 0 & m < 10) {
     my_1();
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;  
    }
    if (m >= 10 & m < 20) {
     my_2();
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16; 
    }
    if (m >= 20 & m < 30) {
     my_3();
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
    }
    if (m >= 30 & m < 40) {
     my_4();
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16; 
    }
    if (m >= 40 & m < 50) {
     my_5();
     
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
    }
    if (m >= 50 & m < 60) {
     my_6();
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
    }
}

2. Все верно. Сначала змейка идет вертикально (это поле для часов), потом горизонтально (это минуты).

Мне бы принцип понять. Почему цифры в итоге вперемешку

 

Komandir
Komandir аватар
Offline
Зарегистрирован: 18.08.2018

Код бредовей еще не видел ! Пока вижу что для десятков минут и единиц минут перепутаны столбцы.

Все конструкции:

      my_...();         
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 

надо записать так:

    h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
      my_...();

То есть сначала задаем столбцы, а потом вызываем отображение !!!

lilik
Offline
Зарегистрирован: 19.10.2017

А мне понравилось это:

switch (analogRead(A1))
{
  case 0 ... 199:   
  break;
  }

Но уже на конструкцию :

if(analogRead(A1)==0 ... 199){}

ругается - где логика?

 

ed2022
Offline
Зарегистрирован: 09.04.2022

Изменил как вы написали и удалил лишние show() и setBrightness(b)

#include <Adafruit_NeoPixel.h>
#include <RTClib.h>
#define k 7
#define l 17

byte q = 155;
byte pin_9 = 9;
int _PWDC = 0;

bool en_151307670_2;
bool en_151307670_3;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
byte b;
byte h1,h2,h3,h4;

RTC_DS3231 rtc;
DateTime t;
Adafruit_NeoPixel pixels_1 = Adafruit_NeoPixel(q, pin_9, NEO_GRB + NEO_KHZ800);


uint32_t time_color = pixels_1.Color(255,255,255);
uint32_t black = pixels_1.Color(0,0,0);

const byte _hhmm[k][l] = {
// 0  1   2   3   4   5   6   7   8   9    10   11   12   13   14   15   16
// h1 h2  h3  h4  
 
  {6, 8,  23, 26, 44, 59, 62, 76, 0,  94,  93,  92,  91,  89,  88,  87,  86},
  {5, 0,  0,  27, 45, 0,  0,  75, 0,  95,  0,   0,   98,  100, 0,   0,   103},
  {4, 0,  0,  28, 46, 0,  0,  74, 78, 112, 0,   0,   109, 107, 0,   0,   104},
  {3, 11, 20, 29, 47, 56, 65, 73, 0,  113, 114, 115, 116, 118, 119, 120, 121},
  {2, 0,  0,  30, 48, 0,  0,  72, 77, 130, 0,   0,   127, 125, 0,   0,   122},
  {1, 0,  0,  31, 49, 0,  0,  71, 0,  131, 0,   0,   134, 136, 0,   0,   139},
  {0, 14, 17, 32, 50, 53, 68, 70, 0,  148, 147, 146, 145, 143, 142, 141, 140},  
};


void my_0() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);  
   pixels_1.setPixelColor(_hhmm[1][h1], black);  
   pixels_1.setPixelColor(_hhmm[2][h1], black);
   pixels_1.setPixelColor(_hhmm[3][h1], black); 
   pixels_1.setPixelColor(_hhmm[4][h1], black);   
   pixels_1.setPixelColor(_hhmm[5][h1], black);  
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.setPixelColor(_hhmm[0][h2], black);
   pixels_1.setPixelColor(_hhmm[3][h2], black);
   pixels_1.setPixelColor(_hhmm[6][h2], black);
   pixels_1.setPixelColor(_hhmm[0][h3], black);   
   pixels_1.setPixelColor(_hhmm[3][h3], black);       
   pixels_1.setPixelColor(_hhmm[6][h3], black);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], black);       
   pixels_1.setPixelColor(_hhmm[2][h4], black);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], black);       
   pixels_1.setPixelColor(_hhmm[5][h4], black);       
   pixels_1.setPixelColor(_hhmm[6][h4], black); 
   pixels_1.show();  
   }
   
//0h
void my_1() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);       
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], black);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], black);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);     
   pixels_1.setPixelColor(_hhmm[6][h4], black);
   pixels_1.show();   
   }

//1h
void my_2() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(&_hhmm[0][h1], black);       
   pixels_1.setPixelColor(&_hhmm[1][h1], black);       
   pixels_1.setPixelColor(&_hhmm[2][h1], black);       
   pixels_1.setPixelColor(&_hhmm[3][h1], black);       
   pixels_1.setPixelColor(&_hhmm[4][h1], black);       
   pixels_1.setPixelColor(&_hhmm[5][h1], black);       
   pixels_1.setPixelColor(&_hhmm[6][h1], black);      
   pixels_1.setPixelColor(&_hhmm[0][h2], black);       
   pixels_1.setPixelColor(&_hhmm[3][h2], black);       
   pixels_1.setPixelColor(&_hhmm[6][h2], black);       
   pixels_1.setPixelColor(&_hhmm[0][h3], black);       
   pixels_1.setPixelColor(&_hhmm[3][h3], black);       
   pixels_1.setPixelColor(&_hhmm[6][h3], black);       
   pixels_1.setPixelColor(&_hhmm[0][h4], black);       
   pixels_1.setPixelColor(&_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(&_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(&_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(&_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(&_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(&_hhmm[6][h4], time_color);  
   pixels_1.show();
   }

//2h
void my_3() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], black);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black); 
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);      
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], black);       
   pixels_1.setPixelColor(_hhmm[5][h4], black);       
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);  
   pixels_1.show(); 
   }   

//3h
 void my_4() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], black);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);    
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);      
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);   
   pixels_1.setPixelColor(_hhmm[6][h4], black);
   pixels_1.show();    
   }
   
//4h
void my_5(){
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);       
   pixels_1.setPixelColor(_hhmm[5][h1], black);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);  
   pixels_1.setPixelColor(_hhmm[0][h2], black);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], black);       
   pixels_1.setPixelColor(_hhmm[0][h3], black);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);      
   pixels_1.setPixelColor(_hhmm[6][h3], black);       
   pixels_1.setPixelColor(_hhmm[0][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], time_color); 
   pixels_1.show(); 
}

//5h
void my_6(){
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);      
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);      
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);        
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[1][h4], black);       
   pixels_1.setPixelColor(_hhmm[2][h4], black);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], black);
   pixels_1.show();
}

//6h
void my_7(){
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);       
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], black);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], black);
   pixels_1.show();
  
}

//7h
void my_8(){
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], black);       
   pixels_1.setPixelColor(_hhmm[2][h1], black);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);       
   pixels_1.setPixelColor(_hhmm[5][h1], black);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);   
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], black);       
   pixels_1.setPixelColor(_hhmm[6][h2], black);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], black);       
   pixels_1.setPixelColor(_hhmm[6][h3], black);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);
   pixels_1.show();
}

//8h
void my_9(){
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);         
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], black);
   pixels_1.show();
}

//9h
void my_10(){
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(_hhmm[0][h1], black);     
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);    
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);    
   pixels_1.setPixelColor(_hhmm[6][h1], black);    
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);    
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);   
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);    
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);    
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);    
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);    
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);   
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[6][h4], black);  
   pixels_1.show(); 

}

void my_11() {
   pixels_1.setBrightness(b);
   pixels_1.setPixelColor(77, time_color);   
   pixels_1.setPixelColor(78, time_color);
   pixels_1.show();
   }

void my_12()
{
    
    if (!(0)) 
    {
         if (! _gen2I) 
        {
            _gen2I = 1;
            _gen2O = 1;
            _gen2P = millis();
        }
    }
     else 
    {
        _gen2I = 0 ;
        _gen2O= 0;
    }
    if (_gen2I) 
    {
          if (_isTimer (_gen2P , 250)) 
        {
             _gen2P = millis();
            _gen2O = ! _gen2O;
        }
    }
    en_151307670_2 = _gen2O;   
    if (en_151307670_2   == 1)
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(77, time_color);
        pixels_1.show();
    }
    else
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(77, black);
        pixels_1.show();
    }
    ;
    en_151307670_3 = _gen2O;  
    if (en_151307670_3   == 1)
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(78, time_color);
        pixels_1.show();
    }
    else
    {
        pixels_1.setBrightness(b);
        pixels_1.setPixelColor(78, black);
        pixels_1.show();
    }
    ;
}
bool _isTimer(unsigned long startTime, unsigned long period)
{
    unsigned long currentTime;
    currentTime = millis();
    if (currentTime>= startTime) 
    {
        return (currentTime>=(startTime + period));
    }
     else 
    {
        return (currentTime >=(4294967295-startTime+period));
    }
}

void my_13() {
    _PWDC = 0;
    
}
ISR(TIMER2_OVF_vect)
{
    TCNT2=100;
    if(_PWDC >= 500)
    {
        asm volatile ("jmp 0x0000");
    }
    else
    {
        _PWDC = _PWDC+1;
    }
    ;
}
       

void setup() {
  rtc.begin();
  pixels_1.begin();  
   TCCR2A = 0x00;
   TCCR2B =  0x07;
   TIMSK2=0x01;
   TCNT2=100;

}

void loop() {
    byte h = t.hour();
    byte m = t.minute();
    my_13();
    t=rtc.now();

   
switch (analogRead(A1))
{
  case 0 ... 199:   
  b = 1; 
  my_11();
  break;
  case 200 ... 499:    
  b = 10;  
  my_12();
  break;
  case 500 ... 849:    
  b = 20;  
  my_12();
  break;
  case 850 ... 979:
  b =30;
  my_12();
  break;
 case 980 ... 1180:
  b = 50;  
  my_12();
  break;
}

    if (h == 0 | h == 10 | h == 20){ 
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;     
     my_1();         
     
    }
    if (h == 1 | h == 11 | h == 21){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
     my_2();
    }
    if (h == 2 | h == 12 | h == 22){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_3(); 
     }
    if (h == 3 | h == 13 | h == 23){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_4(); 
    }
    if (h == 4 | h == 14){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_5(); 
    }
    if (h == 5 | h == 15){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_6(); 
    }
    if (h == 6 | h == 16){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_7(); 
    }
    if (h == 7 | h == 17){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_8(); 
    }
    if (h == 8 | h == 18) {     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_9(); 
    }
    if (h == 9 | h == 19){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_10();     
    }
    if (h >= 0 & h < 10){     
     h1 = 0;
     h2 = 1;
     h3 = 2;
     h4 = 3; 
     my_0(); 
    }
    if (h >= 10 & h < 20){     
     h1 = 0;
     h2 = 1;
     h3 = 2;
     h4 = 3;
     my_2();     
    }  
    if (h >= 20 & h < 25){    
     h1 = 0;
     h2 = 1;
     h3 = 2;
     h4 = 3;
     my_3();         
    }   
    
    if (m == 0 | m == 10 | m == 20 | m == 30 | m == 40 | m == 50) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_1();
                  
    }
    if (m == 1 | m == 11 | m == 21 | m == 31 | m == 41 | m == 51) {         
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_2();       
    }
    if (m == 2 | m == 12 | m == 22 | m == 32 | m == 42 | m == 52) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_3();   
    }
    if (m == 3 | m == 13 | m == 23 | m == 33 | m == 43 | m == 53) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12; 
     my_4(); 
    }
    if (m == 4 | m == 14 | m == 24 | m == 34 | m == 44 | m == 54) {              
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_5();         
    }
    if (m == 5 | m == 15 | m == 25 | m == 35 | m == 45 | m == 55) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_6();  
    }
    if (m == 6 | m == 16 | m == 26 | m == 36 | m == 46 | m == 56) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_7();  
    }
    if (m == 7 | m == 17 | m == 27 | m == 37 | m == 47 | m == 57) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_8();
    }
    if (m == 8 | m == 18 | m == 28 | m == 38 | m == 48 | m == 58) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_9();
    }
    if (m == 9 | m == 19 | m == 29 | m == 39 | m == 49 | m == 59) {     
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
     my_10();     
    }
    if (m >= 0 & m < 10) {    
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
     my_1(); 
    }
    if (m >= 10 & m < 20) {     
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
     my_2();
    }
    if (m >= 20 & m < 30) {     
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
     my_3();
    }
    if (m >= 30 & m < 40) {     
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
     my_4();
    }
    if (m >= 40 & m < 50) {     
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
     my_5();
    }
    if (m >= 50 & m < 60) {     
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
     my_6();
    }
}

И все стало на свои места! У меня сейчас код куда бредовее, кстати! Функций в два раза больше, отдельно на часы и минуты, без массива и соответственно весит он 30544кб. (99%). Он рабочий, но прямо впритык! Это бред! Сейчас 40%! Спасибо Добрый человек! Удачи и здоровья вам, Komandir!

 

Komandir
Komandir аватар
Offline
Зарегистрирован: 18.08.2018
byte h = t.hour();
byte m = t.minute();
my_13();
t=rtc.now();

Тоже надо перевернуть:

t=rtc.now();

должен быть раньше чем:

byte h = t.hour();
byte m = t.minute();

show() и setBrightness(b) должны быть ОДИН раз в конце LOOP !

И + я совсем не разбирался зачем там прерывания и другая лабуда с PWDC ... смотрел только на заявленные проблемы с порядком цифр !

b707
Offline
Зарегистрирован: 26.05.2017

Налицо абсолютно бредовое проектирование схемы и кода. Понимаете, если вам надо вывести на экран двухзначное число, это не значит что надо придумать 100 функций для каждого варианта от 00 до 99. Вместо этого сначала выводим первую цифру, а потом вторую.

Если бы вы сделали змейки для каждой цифры часов и минут одинаковые - можно было обойтись всго десятью функциями для цифр от 0 до 9

ed2022
Offline
Зарегистрирован: 09.04.2022

Ок, поменял местами. Вы имеете ввиду, что нужно удалить show() и setBrightness(b) из всех функций до void setup() тоже? Только в void loop() в конце один раз? На счет PWDC это я слизал так называемую защиту от зависаний. Черт его знает работает оно или нет, ах-ха-ха! Ну, пусть будет! Вроде не мешает.

Komandir
Komandir аватар
Offline
Зарегистрирован: 18.08.2018

ed2022 пишет:

...Вы имеете ввиду, что нужно удалить show() и setBrightness(b) из всех функций до void setup() тоже? Только в void loop() в конце один раз...

ДА

ed2022
Offline
Зарегистрирован: 09.04.2022

Не знаю, понятно ли, что я отвечаю конкретно кому-то, нажимая "ответить". 

b707, все верно, у меня как раз такая схема 10 функций для чисел от 0 до 9, и пару функций для режима двоеточий и функция watchdog. А была действительно громоздкая на 20+ функций для часов и минут отдельно

ЕвгенийП
ЕвгенийП аватар
Offline
Зарегистрирован: 25.05.2015

lilik пишет:

А мне понравилось это:

switch (analogRead(A1))
{
  case 0 ... 199:   
  break;
  }

Но уже на конструкцию :

if(analogRead(A1)==0 ... 199){}

ругается - где логика?

«Ох, как он сетовал!
Где закон? Нету, мол!»

В.С. Высоцкий.

ed2022
Offline
Зарегистрирован: 09.04.2022

Komandir пишет:

ed2022 пишет:

...Вы имеете ввиду, что нужно удалить show() и setBrightness(b) из всех функций до void setup() тоже? Только в void loop() в конце один раз...

ДА

Все удалил. Все работает. Двоеточие замигало в два раза чаще, вроде в такт секундам, как и планировалось. Раньше чуть запаздывало. Спасибо

Komandir
Komandir аватар
Offline
Зарегистрирован: 18.08.2018
    if (h == 0 | h == 10 | h == 20){ 
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;     
     my_1();         
     
    }
    if (h == 1 | h == 11 | h == 21){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
     my_2();
    }
    if (h == 2 | h == 12 | h == 22){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_3(); 
     }
    if (h == 3 | h == 13 | h == 23){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_4(); 
    }
    if (h == 4 | h == 14){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_5(); 
    }
    if (h == 5 | h == 15){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_6(); 
    }
    if (h == 6 | h == 16){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_7(); 
    }
    if (h == 7 | h == 17){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_8(); 
    }
    if (h == 8 | h == 18) {     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_9(); 
    }
    if (h == 9 | h == 19){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_10();     
    }

Нужно заменить на:

h1 = 4;
h2 = 5;
h3 = 6;
h4 = 7;   
if (h == 0 | h == 10 | h == 20) my_1();
if (h == 1 | h == 11 | h == 21) my_2();
if (h == 2 | h == 12 | h == 22) my_3();
if (h == 3 | h == 13 | h == 23) my_4();
if (h == 4 | h == 14) my_5();
if (h == 5 | h == 15) my_6();
if (h == 6 | h == 16) my_7();
if (h == 7 | h == 17) my_8();
if (h == 8 | h == 18) my_9();
if (h == 9 | h == 19) my_10();

И так же для других разрядов ...

ed2022
Offline
Зарегистрирован: 09.04.2022

Komandir пишет:

    if (h == 0 | h == 10 | h == 20){ 
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;     
     my_1();         
     
    }
    if (h == 1 | h == 11 | h == 21){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7; 
     my_2();
    }
    if (h == 2 | h == 12 | h == 22){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_3(); 
     }
    if (h == 3 | h == 13 | h == 23){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_4(); 
    }
    if (h == 4 | h == 14){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_5(); 
    }
    if (h == 5 | h == 15){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_6(); 
    }
    if (h == 6 | h == 16){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_7(); 
    }
    if (h == 7 | h == 17){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_8(); 
    }
    if (h == 8 | h == 18) {     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_9(); 
    }
    if (h == 9 | h == 19){     
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
     my_10();     
    }

Нужно заменить на:

h1 = 4;
h2 = 5;
h3 = 6;
h4 = 7;   
if (h == 0 | h == 10 | h == 20) my_1();
if (h == 1 | h == 11 | h == 21) my_2();
if (h == 2 | h == 12 | h == 22) my_3();
if (h == 3 | h == 13 | h == 23) my_4();
if (h == 4 | h == 14) my_5();
if (h == 5 | h == 15) my_6();
if (h == 6 | h == 16) my_7();
if (h == 7 | h == 17) my_8();
if (h == 8 | h == 18) my_9();
if (h == 9 | h == 19) my_10();

И так же для других разрядов ...

#include <Adafruit_NeoPixel.h>
#include <RTClib.h>
#define k 7
#define l 17

byte q = 155;
byte pin_9 = 9;
int _PWDC = 0;

bool en_151307670_2;
bool en_151307670_3;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
byte b;
byte h1,h2,h3,h4;

RTC_DS3231 rtc;
DateTime t;
Adafruit_NeoPixel pixels_1 = Adafruit_NeoPixel(q, pin_9, NEO_GRB + NEO_KHZ800);


uint32_t time_color = pixels_1.Color(255,255,255);
uint32_t black = pixels_1.Color(0,0,0);

const byte _hhmm[k][l] = {
// 0  1   2   3   4   5   6   7   8   9    10   11   12   13   14   15   16
// h1 h2  h3  h4  
 
  {6, 8,  23, 26, 44, 59, 62, 76, 0,  94,  93,  92,  91,  89,  88,  87,  86},
  {5, 0,  0,  27, 45, 0,  0,  75, 0,  95,  0,   0,   98,  100, 0,   0,   103},
  {4, 0,  0,  28, 46, 0,  0,  74, 78, 112, 0,   0,   109, 107, 0,   0,   104},
  {3, 11, 20, 29, 47, 56, 65, 73, 0,  113, 114, 115, 116, 118, 119, 120, 121},
  {2, 0,  0,  30, 48, 0,  0,  72, 77, 130, 0,   0,   127, 125, 0,   0,   122},
  {1, 0,  0,  31, 49, 0,  0,  71, 0,  131, 0,   0,   134, 136, 0,   0,   139},
  {0, 14, 17, 32, 50, 53, 68, 70, 0,  148, 147, 146, 145, 143, 142, 141, 140},  
};


void my_0() {   
   pixels_1.setPixelColor(_hhmm[0][h1], black);  
   pixels_1.setPixelColor(_hhmm[1][h1], black);  
   pixels_1.setPixelColor(_hhmm[2][h1], black);
   pixels_1.setPixelColor(_hhmm[3][h1], black); 
   pixels_1.setPixelColor(_hhmm[4][h1], black);   
   pixels_1.setPixelColor(_hhmm[5][h1], black);  
   pixels_1.setPixelColor(_hhmm[6][h1], black);
   pixels_1.setPixelColor(_hhmm[0][h2], black);
   pixels_1.setPixelColor(_hhmm[3][h2], black);
   pixels_1.setPixelColor(_hhmm[6][h2], black);
   pixels_1.setPixelColor(_hhmm[0][h3], black);   
   pixels_1.setPixelColor(_hhmm[3][h3], black);       
   pixels_1.setPixelColor(_hhmm[6][h3], black);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], black);       
   pixels_1.setPixelColor(_hhmm[2][h4], black);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], black);       
   pixels_1.setPixelColor(_hhmm[5][h4], black);       
   pixels_1.setPixelColor(_hhmm[6][h4], black);     
   }
   
//0h
void my_1() {   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);       
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], black);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], black);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);     
   pixels_1.setPixelColor(_hhmm[6][h4], black);      
   }

//1h
void my_2() {   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], black);       
   pixels_1.setPixelColor(_hhmm[2][h1], black);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);       
   pixels_1.setPixelColor(_hhmm[5][h1], black);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);      
   pixels_1.setPixelColor(_hhmm[0][h2], black);       
   pixels_1.setPixelColor(_hhmm[3][h2], black);       
   pixels_1.setPixelColor(_hhmm[6][h2], black);       
   pixels_1.setPixelColor(_hhmm[0][h3], black);       
   pixels_1.setPixelColor(_hhmm[3][h3], black);       
   pixels_1.setPixelColor(_hhmm[6][h3], black);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);    
   }

//2h
void my_3() {   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], black);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black); 
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);      
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], black);       
   pixels_1.setPixelColor(_hhmm[5][h4], black);       
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);     
   }   

//3h
 void my_4() {   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], black);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);    
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);      
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);   
   pixels_1.setPixelColor(_hhmm[6][h4], black);       
   }
   
//4h
void my_5(){   
   pixels_1.setPixelColor(_hhmm[0][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);       
   pixels_1.setPixelColor(_hhmm[5][h1], black);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);  
   pixels_1.setPixelColor(_hhmm[0][h2], black);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], black);       
   pixels_1.setPixelColor(_hhmm[0][h3], black);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);      
   pixels_1.setPixelColor(_hhmm[6][h3], black);       
   pixels_1.setPixelColor(_hhmm[0][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);    
}

//5h
void my_6(){   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);      
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);      
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);        
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[1][h4], black);       
   pixels_1.setPixelColor(_hhmm[2][h4], black);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], black);   
}

//6h
void my_7(){   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);       
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], black);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], black);   
  
}

//7h
void my_8(){   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], black);       
   pixels_1.setPixelColor(_hhmm[2][h1], black);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);       
   pixels_1.setPixelColor(_hhmm[5][h1], black);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);   
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], black);       
   pixels_1.setPixelColor(_hhmm[6][h2], black);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], black);       
   pixels_1.setPixelColor(_hhmm[6][h3], black);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], time_color);  
}

//8h
void my_9(){   
   pixels_1.setPixelColor(_hhmm[0][h1], black);       
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h1], black);         
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);       
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[3][h4], black);       
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);       
   pixels_1.setPixelColor(_hhmm[6][h4], black);   
}

//9h
void my_10(){   
   pixels_1.setPixelColor(_hhmm[0][h1], black);     
   pixels_1.setPixelColor(_hhmm[1][h1], time_color);       
   pixels_1.setPixelColor(_hhmm[2][h1], time_color);
   pixels_1.setPixelColor(_hhmm[3][h1], black);       
   pixels_1.setPixelColor(_hhmm[4][h1], black);    
   pixels_1.setPixelColor(_hhmm[5][h1], time_color);    
   pixels_1.setPixelColor(_hhmm[6][h1], black);    
   pixels_1.setPixelColor(_hhmm[0][h2], time_color);    
   pixels_1.setPixelColor(_hhmm[3][h2], time_color);   
   pixels_1.setPixelColor(_hhmm[6][h2], time_color);    
   pixels_1.setPixelColor(_hhmm[0][h3], time_color);    
   pixels_1.setPixelColor(_hhmm[3][h3], time_color);    
   pixels_1.setPixelColor(_hhmm[6][h3], time_color);    
   pixels_1.setPixelColor(_hhmm[0][h4], black);       
   pixels_1.setPixelColor(_hhmm[1][h4], time_color);   
   pixels_1.setPixelColor(_hhmm[2][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[3][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[4][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[5][h4], time_color);    
   pixels_1.setPixelColor(_hhmm[6][h4], black);   

}

void my_11() {    pixels_1.setPixelColor(77, time_color);   
   pixels_1.setPixelColor(78, time_color);
   
   }

void my_12()
{
    
    if (!(0)) 
    {
         if (! _gen2I) 
        {
            _gen2I = 1;
            _gen2O = 1;
            _gen2P = millis();
        }
    }
     else 
    {
        _gen2I = 0 ;
        _gen2O= 0;
    }
    if (_gen2I) 
    {
          if (_isTimer (_gen2P , 250)) 
        {
             _gen2P = millis();
            _gen2O = ! _gen2O;
        }
    }
    en_151307670_2 = _gen2O;   
    if (en_151307670_2   == 1)
    {       
        pixels_1.setPixelColor(77, time_color);       
    }
    else    {
        
        pixels_1.setPixelColor(77, black);        
    }
    ;
    en_151307670_3 = _gen2O;  
    if (en_151307670_3   == 1)    {
        
        pixels_1.setPixelColor(78, time_color);        
    }
    else
    {        
        pixels_1.setPixelColor(78, black);        
    }
    ;
}
bool _isTimer(unsigned long startTime, unsigned long period)
{
    unsigned long currentTime;
    currentTime = millis();
    if (currentTime>= startTime) 
    {
        return (currentTime>=(startTime + period));
    }
     else 
    {
        return (currentTime >=(4294967295-startTime+period));
    }
}

void my_13() {
    _PWDC = 0;
    
}
ISR(TIMER2_OVF_vect)
{
    TCNT2=100;
    if(_PWDC >= 500)
    {
        asm volatile ("jmp 0x0000");
    }
    else
    {
        _PWDC = _PWDC+1;
    }
    ;
}
       

void setup() {
  rtc.begin();
  pixels_1.begin();  
   TCCR2A = 0x00;
   TCCR2B =  0x07;
   TIMSK2=0x01;
   TCNT2=100;

}

void loop() {
    t=rtc.now();
    byte h = t.hour();
    byte m = t.minute();   
    my_13();   
   
switch (analogRead(A1))
{
  case 0 ... 199:   
  b = 1; 
  my_11();
  break;
  case 200 ... 499:    
  b = 10;  
  my_12();
  break;
  case 500 ... 849:    
  b = 20;  
  my_12();
  break;
  case 850 ... 979:
  b =30;
  my_12();
  break;
 case 980 ... 1180:
  b = 50;  
  my_12();
  break;
}
     h1 = 4;
     h2 = 5;
     h3 = 6;
     h4 = 7;
    if (h == 0 | h == 10 | h == 20){         
     my_1();         
     
    }
    if (h == 1 | h == 11 | h == 21){     
     my_2();
    }
    if (h == 2 | h == 12 | h == 22){     
     my_3(); 
     }
    if (h == 3 | h == 13 | h == 23){     
     my_4(); 
    }
    if (h == 4 | h == 14){     
     my_5(); 
    }
    if (h == 5 | h == 15){     
     my_6(); 
    }
    if (h == 6 | h == 16){    
     my_7(); 
    }
    if (h == 7 | h == 17){    
     my_8(); 
    }
    if (h == 8 | h == 18){    
     my_9(); 
    }
    if (h == 9 | h == 19){     
     my_10();     
    }
     h1 = 0;
     h2 = 1;
     h3 = 2;
     h4 = 3;
    if (h >= 0 & h < 10){      
     my_0(); 
    }
    if (h >= 10 & h < 20){     
     my_2();     
    }  
    if (h >= 20 & h < 25){     
     my_3();         
    }   
     h1 = 13;
     h2 = 14;
     h3 = 15;
     h4 = 16;
    if (m == 0 | m == 10 | m == 20 | m == 30 | m == 40 | m == 50) {     
     my_1();
                  
    }
    if (m == 1 | m == 11 | m == 21 | m == 31 | m == 41 | m == 51) {     
     my_2();       
    }
    if (m == 2 | m == 12 | m == 22 | m == 32 | m == 42 | m == 52) {     
     my_3();   
    }
    if (m == 3 | m == 13 | m == 23 | m == 33 | m == 43 | m == 53) {      
     my_4(); 
    }
    if (m == 4 | m == 14 | m == 24 | m == 34 | m == 44 | m == 54) {     
     my_5();         
    }
    if (m == 5 | m == 15 | m == 25 | m == 35 | m == 45 | m == 55) {    
     my_6();  
    }
    if (m == 6 | m == 16 | m == 26 | m == 36 | m == 46 | m == 56) {     
     my_7();  
    }
    if (m == 7 | m == 17 | m == 27 | m == 37 | m == 47 | m == 57) {     
     my_8();
    }
    if (m == 8 | m == 18 | m == 28 | m == 38 | m == 48 | m == 58) {     
     my_9();
    }
    if (m == 9 | m == 19 | m == 29 | m == 39 | m == 49 | m == 59) {     
      my_10();     
    }
     h1 = 9;
     h2 = 10;
     h3 = 11;
     h4 = 12;
    if (m >= 0 & m < 10) {     
     my_1(); 
    }
    if (m >= 10 & m < 20) {     
     my_2();
    }
    if (m >= 20 & m < 30) {     
     my_3();
    }
    if (m >= 30 & m < 40) {     
     my_4();
    }
    if (m >= 40 & m < 50) {     
     my_5();
    }
    if (m >= 50 & m < 60) {     
     my_6();
    }
    pixels_1.setBrightness(b);
    pixels_1.show();
}

Ахах, 37%!!! Гениально! У меня там еще есть DHT22. Когда было 99%, я искал по сусекам несчастные килобайты, чтобы температуру и влажность еще завести. Вот теперь есть где разгуляться! Я в программировании профан, поэтому для меня это очень изящное решение!

Komandir
Komandir аватар
Offline
Зарегистрирован: 18.08.2018

Первой строкой в loop пишем pixels_1.clear(); и тогда ВСЕ строки где пикселям присваивается цвет black УДАЛЯЕМ !!!

ed2022
Offline
Зарегистрирован: 09.04.2022

Komandir пишет:

Первой строкой в loop пишем pixels_1.clear(); и тогда ВСЕ строки где пикселям присваивается цвет black УДАЛЯЕМ !!!

#include <Adafruit_NeoPixel.h>
#include <RTClib.h>
#define k 7
#define l 17

byte q = 155;
byte pin_9 = 9;
int _PWDC = 0;

bool en_151307670_2;
bool en_151307670_3;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
byte b;
byte h1, h2, h3, h4;

RTC_DS3231 rtc;
DateTime t;
Adafruit_NeoPixel pixels_1 = Adafruit_NeoPixel(q, pin_9, NEO_GRB + NEO_KHZ800);


uint32_t time_color = pixels_1.Color(255, 255, 255);
uint32_t black = pixels_1.Color(0, 0, 0);

const byte _hhmm[k][l] = {
  // 0  1   2   3   4   5   6   7   8   9    10   11   12   13   14   15   16
  // h1 h2  h3  h4

  {6, 8,  23, 26, 44, 59, 62, 76, 0,  94,  93,  92,  91,  89,  88,  87,  86},
  {5, 0,  0,  27, 45, 0,  0,  75, 0,  95,  0,   0,   98,  100, 0,   0,   103},
  {4, 0,  0,  28, 46, 0,  0,  74, 78, 112, 0,   0,   109, 107, 0,   0,   104},
  {3, 11, 20, 29, 47, 56, 65, 73, 0,  113, 114, 115, 116, 118, 119, 120, 121},
  {2, 0,  0,  30, 48, 0,  0,  72, 77, 130, 0,   0,   127, 125, 0,   0,   122},
  {1, 0,  0,  31, 49, 0,  0,  71, 0,  131, 0,   0,   134, 136, 0,   0,   139},
  {0, 14, 17, 32, 50, 53, 68, 70, 0,  148, 147, 146, 145, 143, 142, 141, 140},
};

//0h
void my_1() {  
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);
  pixels_1.setPixelColor(_hhmm[2][h1], time_color);
  pixels_1.setPixelColor(_hhmm[3][h1], time_color);
  pixels_1.setPixelColor(_hhmm[4][h1], time_color);
  pixels_1.setPixelColor(_hhmm[5][h1], time_color); 
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);  
  pixels_1.setPixelColor(_hhmm[6][h2], time_color);
  pixels_1.setPixelColor(_hhmm[0][h3], time_color);  
  pixels_1.setPixelColor(_hhmm[6][h3], time_color);  
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color);
  pixels_1.setPixelColor(_hhmm[3][h4], time_color);
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);
 
}

//1h
void my_2() {
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color);
  pixels_1.setPixelColor(_hhmm[3][h4], time_color);
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);
  pixels_1.setPixelColor(_hhmm[6][h4], time_color);
}

//2h
void my_3() {  
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[4][h1], time_color);
  pixels_1.setPixelColor(_hhmm[5][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);
  pixels_1.setPixelColor(_hhmm[3][h2], time_color);
  pixels_1.setPixelColor(_hhmm[6][h2], time_color);
  pixels_1.setPixelColor(_hhmm[0][h3], time_color);
  pixels_1.setPixelColor(_hhmm[3][h3], time_color);
  pixels_1.setPixelColor(_hhmm[6][h3], time_color);  
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color);  
  pixels_1.setPixelColor(_hhmm[6][h4], time_color);
}

//3h
void my_4() {
  
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[5][h1], time_color); 
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);
  pixels_1.setPixelColor(_hhmm[3][h2], time_color);
  pixels_1.setPixelColor(_hhmm[6][h2], time_color);
  pixels_1.setPixelColor(_hhmm[0][h3], time_color);
  pixels_1.setPixelColor(_hhmm[3][h3], time_color);
  pixels_1.setPixelColor(_hhmm[6][h3], time_color);  
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color); 
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);  
}

//4h
void my_5() {
  pixels_1.setPixelColor(_hhmm[0][h1], time_color);
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);
  pixels_1.setPixelColor(_hhmm[2][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[3][h2], time_color);  
  pixels_1.setPixelColor(_hhmm[3][h3], time_color);  
  pixels_1.setPixelColor(_hhmm[0][h4], time_color);
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color);
  pixels_1.setPixelColor(_hhmm[3][h4], time_color);
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);
  pixels_1.setPixelColor(_hhmm[6][h4], time_color);
}

//5h
void my_6() {  
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);
  pixels_1.setPixelColor(_hhmm[2][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[5][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);
  pixels_1.setPixelColor(_hhmm[3][h2], time_color);
  pixels_1.setPixelColor(_hhmm[6][h2], time_color);
  pixels_1.setPixelColor(_hhmm[0][h3], time_color);
  pixels_1.setPixelColor(_hhmm[3][h3], time_color);
  pixels_1.setPixelColor(_hhmm[6][h3], time_color);
  pixels_1.setPixelColor(_hhmm[0][h4], time_color);  
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);  
}

//6h
void my_7() {  
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);
  pixels_1.setPixelColor(_hhmm[2][h1], time_color);
  pixels_1.setPixelColor(_hhmm[3][h1], time_color);
  pixels_1.setPixelColor(_hhmm[4][h1], time_color);
  pixels_1.setPixelColor(_hhmm[5][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);
  pixels_1.setPixelColor(_hhmm[3][h2], time_color);
  pixels_1.setPixelColor(_hhmm[6][h2], time_color);
  pixels_1.setPixelColor(_hhmm[0][h3], time_color);
  pixels_1.setPixelColor(_hhmm[3][h3], time_color);
  pixels_1.setPixelColor(_hhmm[6][h3], time_color); 
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);  
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);

}

//7h
void my_8() {  
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);  
  pixels_1.setPixelColor(_hhmm[0][h3], time_color); 
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color);
  pixels_1.setPixelColor(_hhmm[3][h4], time_color);
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);
  pixels_1.setPixelColor(_hhmm[6][h4], time_color);
}

//8h
void my_9() {  
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);
  pixels_1.setPixelColor(_hhmm[2][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[4][h1], time_color);
  pixels_1.setPixelColor(_hhmm[5][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);
  pixels_1.setPixelColor(_hhmm[3][h2], time_color);
  pixels_1.setPixelColor(_hhmm[6][h2], time_color);
  pixels_1.setPixelColor(_hhmm[0][h3], time_color);
  pixels_1.setPixelColor(_hhmm[3][h3], time_color);
  pixels_1.setPixelColor(_hhmm[6][h3], time_color);  
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color);  
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);  
}

//9h
void my_10() {
  
  pixels_1.setPixelColor(_hhmm[1][h1], time_color);
  pixels_1.setPixelColor(_hhmm[2][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[5][h1], time_color);  
  pixels_1.setPixelColor(_hhmm[0][h2], time_color);
  pixels_1.setPixelColor(_hhmm[3][h2], time_color);
  pixels_1.setPixelColor(_hhmm[6][h2], time_color);
  pixels_1.setPixelColor(_hhmm[0][h3], time_color);
  pixels_1.setPixelColor(_hhmm[3][h3], time_color);
  pixels_1.setPixelColor(_hhmm[6][h3], time_color);  
  pixels_1.setPixelColor(_hhmm[1][h4], time_color);
  pixels_1.setPixelColor(_hhmm[2][h4], time_color);
  pixels_1.setPixelColor(_hhmm[3][h4], time_color);
  pixels_1.setPixelColor(_hhmm[4][h4], time_color);
  pixels_1.setPixelColor(_hhmm[5][h4], time_color);
}

void my_11() {
  pixels_1.setPixelColor(77, time_color);
  pixels_1.setPixelColor(78, time_color);

}

void my_12()
{

  if (!(0))
  {
    if (! _gen2I)
    {
      _gen2I = 1;
      _gen2O = 1;
      _gen2P = millis();
    }
  }
  else
  {
    _gen2I = 0 ;
    _gen2O = 0;
  }
  if (_gen2I)
  {
    if (_isTimer (_gen2P , 250))
    {
      _gen2P = millis();
      _gen2O = ! _gen2O;
    }
  }
  en_151307670_2 = _gen2O;
  if (en_151307670_2   == 1)
  {
    pixels_1.setPixelColor(77, time_color);
  }
  else    {

    pixels_1.setPixelColor(77, black);
  }
  ;
  en_151307670_3 = _gen2O;
  if (en_151307670_3   == 1)    {

    pixels_1.setPixelColor(78, time_color);
  }
  else
  {
    pixels_1.setPixelColor(78, black);
  }
  ;
}
bool _isTimer(unsigned long startTime, unsigned long period)
{
  unsigned long currentTime;
  currentTime = millis();
  if (currentTime >= startTime)
  {
    return (currentTime >= (startTime + period));
  }
  else
  {
    return (currentTime >= (4294967295 - startTime + period));
  }
}

void my_13() {
  _PWDC = 0;

}
ISR(TIMER2_OVF_vect)
{
  TCNT2 = 100;
  if (_PWDC >= 500)
  {
    asm volatile ("jmp 0x0000");
  }
  else
  {
    _PWDC = _PWDC + 1;
  }
  ;
}


void setup() {
  rtc.begin();
  pixels_1.begin();
  TCCR2A = 0x00;
  TCCR2B =  0x07;
  TIMSK2 = 0x01;
  TCNT2 = 100;

}

void loop() {
  pixels_1.clear();
  t = rtc.now();
  byte h = t.hour();
  byte m = t.minute();
  my_13();

  switch (analogRead(A1))
  {
    case 0 ... 199:
      b = 1;
      my_11();
      break;
    case 200 ... 499:
      b = 10;
      my_12();
      break;
    case 500 ... 849:
      b = 20;
      my_12();
      break;
    case 850 ... 979:
      b = 30;
      my_12();
      break;
    case 980 ... 1180:
      b = 50;
      my_12();
      break;
  }
  h1 = 4;
  h2 = 5;
  h3 = 6;
  h4 = 7;
  if (h == 0 | h == 10 | h == 20)my_1();
  if (h == 1 | h == 11 | h == 21)my_2();
  if (h == 2 | h == 12 | h == 22)my_3();
  if (h == 3 | h == 13 | h == 23)my_4();
  if (h == 4 | h == 14)my_5();
  if (h == 5 | h == 15)my_6();
  if (h == 6 | h == 16)my_7();
  if (h == 7 | h == 17)my_8();
  if (h == 8 | h == 18)my_9();
  if (h == 9 | h == 19)my_10();
  h1 = 0;
  h2 = 1;
  h3 = 2;
  h4 = 3;  
  if (h >= 10 & h < 20)my_2();
  if (h >= 20 & h < 25)my_3();
  h1 = 13;
  h2 = 14;
  h3 = 15;
  h4 = 16;
  if (m == 0 | m == 10 | m == 20 | m == 30 | m == 40 | m == 50)my_1();
  if (m == 1 | m == 11 | m == 21 | m == 31 | m == 41 | m == 51)my_2();
  if (m == 2 | m == 12 | m == 22 | m == 32 | m == 42 | m == 52)my_3();
  if (m == 3 | m == 13 | m == 23 | m == 33 | m == 43 | m == 53)my_4();
  if (m == 4 | m == 14 | m == 24 | m == 34 | m == 44 | m == 54)my_5();
  if (m == 5 | m == 15 | m == 25 | m == 35 | m == 45 | m == 55)my_6();
  if (m == 6 | m == 16 | m == 26 | m == 36 | m == 46 | m == 56)my_7();
  if (m == 7 | m == 17 | m == 27 | m == 37 | m == 47 | m == 57)my_8();
  if (m == 8 | m == 18 | m == 28 | m == 38 | m == 48 | m == 58)my_9();
  if (m == 9 | m == 19 | m == 29 | m == 39 | m == 49 | m == 59)my_10();
  h1 = 9;
  h2 = 10;
  h3 = 11;
  h4 = 12;
  if (m >= 0 & m < 10)my_1();
  if (m >= 10 & m < 20)my_2();
  if (m >= 20 & m < 30)my_3();
  if (m >= 30 & m < 40)my_4();
  if (m >= 40 & m < 50)my_5();
  if (m >= 50 & m < 60)my_6();
  pixels_1.setBrightness(b);
  pixels_1.show();
}

Прикольно, 31%...

Было 99%,  стало 31%. Я знал, что простые часы не могут весить 99%, поэтому копал везде. Но чтобы больше чем вполовину разгрузить, я конечно не подозревал. "Я просто похлопаю(c)"

lilik
Offline
Зарегистрирован: 19.10.2017

ЕвгенийП пишет:

lilik пишет:

А мне понравилось это:

switch (analogRead(A1))
{
  case 0 ... 199:   
  break;
  }

Но уже на конструкцию :

if(analogRead(A1)==0 ... 199){}

ругается - где логика?

«Ох, как он сетовал!
Где закон? Нету, мол!»

В.С. Высоцкий.

:-)

Ну, да...

Раз в рамках case работает конструкция min ... max почему в других не встречается?

ЕвгенийП
ЕвгенийП аватар
Offline
Зарегистрирован: 25.05.2015

:-)

rkit
Offline
Зарегистрирован: 23.11.2016

b707 пишет:
Налицо абсолютно бредовое проектирование схемы и кода. Понимаете, если вам надо вывести на экран двухзначное число, это не значит что надо придумать 100 функций для каждого варианта от 00 до 99. Вместо этого сначала выводим первую цифру, а потом вторую. Если бы вы сделали змейки для каждой цифры часов и минут одинаковые - можно было обойтись всго десятью функциями для цифр от 0 до 9

Элементарно решается одной формулой  в две строчки для проекции пикселей. Или таблицей, если лень мозги напрягать.