Ребята спасибо всем огромное форум пушка вот скетч кому интересно опробуйте
#include <SPI.h>
bool _gtv1;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
byte _74HC5952OB1 = 0;
byte _74HC5952OB2 = 0;
byte _74HC5952TB = 0;
bool _74HC5952NS = 0;
byte _74HC5951OB1 = 0;
byte _74HC5951OB2 = 0;
byte _74HC5951TB = 0;
bool _74HC5951NS = 0;
bool _count1I = 0;
int _count1_Value = 0;
bool _count1MaxLO = 0;
bool _bounseInputD2S = 0;
bool _bounseInputD2O = 0;
unsigned long _bounseInputD2P = 0UL;
void setup()
{
pinMode(2, INPUT_PULLUP);
_bounseInputD2O = digitalRead(2);
SPI.begin();
pinMode(10, OUTPUT);
pinMode(8, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
bool _bounceInputTmpD2 = (digitalRead (2));
if (_bounseInputD2S)
{
if (millis() >= (_bounseInputD2P + 40))
{_bounseInputD2O= _bounceInputTmpD2; _bounseInputD2S=0;}
}
else
{
if (_bounceInputTmpD2 != _bounseInputD2O )
{_bounseInputD2S=1; _bounseInputD2P = millis();}
}
//Плата:1
_74HC5952NS = 0;
bitWrite(_74HC5952TB, 0, 0);
bitWrite(_74HC5952TB, 1, 0);
bitWrite(_74HC5952TB, 2, 0);
bitWrite(_74HC5952TB, 3, 0);
bitWrite(_74HC5952TB, 4, 0);
bitWrite(_74HC5952TB, 5, 0);
bitWrite(_74HC5952TB, 6, 0);
bitWrite(_74HC5952TB, 7, 0);
if(! (_74HC5952TB == _74HC5952OB1)){_74HC5952OB1 = _74HC5952TB; _74HC5952NS = 1;}
bitWrite(_74HC5952TB, 0, 0);
bitWrite(_74HC5952TB, 1, 0);
bitWrite(_74HC5952TB, 2, 0);
bitWrite(_74HC5952TB, 3, 0);
bitWrite(_74HC5952TB, 4, 0);
bitWrite(_74HC5952TB, 5, 0);
bitWrite(_74HC5952TB, 6, 0);
bitWrite(_74HC5952TB, 7, 0);
if(! (_74HC5952TB == _74HC5952OB2)){_74HC5952OB2 = _74HC5952TB; _74HC5952NS = 1;}
if (_74HC5952NS) {
digitalWrite(8, 0);
SPI.transfer(_74HC5952OB2);
SPI.transfer(_74HC5952OB1);
digitalWrite(8, 1);}
if (!(_bounseInputD2O)) {if (! _gen1I) { _gen1I = 1; _gen1O = 1; _gen1P = millis(); } } else { _gen1I = 0 ; _gen1O= 0; } if (_gen1I ) { if (_gen1O) { if ( _isTimer( _gen1P , 50 )) { _gen1P = millis(); _gen1O = 0; } } else { if ( _isTimer( _gen1P , 50 )) { _gen1P = millis(); _gen1O = 1; } } }
if (_gtv1){_count1_Value = 0;} else {
if (_gen1O){
if ( ! _count1I) {
_count1I = 1;
_count1_Value = _count1_Value + 1;
}} else {
_count1I = 0;}
}
_count1MaxLO = _count1_Value >= 16;
_74HC5951NS = 0;
bitWrite(_74HC5951TB, 0, (_count1_Value == 1));
bitWrite(_74HC5951TB, 1, (_count1_Value == 2));
bitWrite(_74HC5951TB, 2, (_count1_Value == 3));
bitWrite(_74HC5951TB, 3, (_count1_Value == 4));
bitWrite(_74HC5951TB, 4, (_count1_Value == 5));
bitWrite(_74HC5951TB, 5, (_count1_Value == 6));
bitWrite(_74HC5951TB, 6, (_count1_Value == 7));
bitWrite(_74HC5951TB, 7, (_count1_Value == 8));
if(! (_74HC5951TB == _74HC5951OB1)){_74HC5951OB1 = _74HC5951TB; _74HC5951NS = 1;}
bitWrite(_74HC5951TB, 0, (_count1_Value == 9));
bitWrite(_74HC5951TB, 1, (_count1_Value == 10));
bitWrite(_74HC5951TB, 2, (_count1_Value == 11));
bitWrite(_74HC5951TB, 3, (_count1_Value == 12));
bitWrite(_74HC5951TB, 4, (_count1_Value == 13));
bitWrite(_74HC5951TB, 5, (_count1_Value == 14));
bitWrite(_74HC5951TB, 6, (_count1_Value == 15));
bitWrite(_74HC5951TB, 7, (_count1_Value == 16));
if(! (_74HC5951TB == _74HC5951OB2)){_74HC5951OB2 = _74HC5951TB; _74HC5951NS = 1;}
if (_74HC5951NS) {
digitalWrite(8, 0);
SPI.transfer(_74HC5951OB2);
SPI.transfer(_74HC5951OB1);
digitalWrite(8, 1);}
_gtv1 = _count1MaxLO;
}
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));}
}