Вс июн 26, 2022 04:26:45
Вс июн 26, 2022 08:06:10
Вс июн 26, 2022 08:27:04
Вс июн 26, 2022 10:00:43
Вс июн 26, 2022 15:05:26
Вс июн 26, 2022 15:59:54
Вс июн 26, 2022 17:18:15
Вс июн 26, 2022 19:44:18
Вс июн 26, 2022 20:14:26
Вт июн 28, 2022 15:20:14
//Подключаем библиотеку
#include <GyverPWM.h>
struct _poligonInexes
{
int minIndex;
int maxIndex;
}
;
int _Poligon_InArray_1[6] = {0, 300, 900, 2000, 4000, 6000};
int _Poligon_OutArray_1[6] = {0, 90, 150, 190, 230, 255};
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _trgrt1 = 0;
bool _trgrt1I = 0;
bool _count1I = 0;
int _count1_Value = 0;
bool _bounseInputD12S = 0;
bool _bounseInputD12O = 0;
unsigned long _bounseInputD12P = 0UL;
void setup()
{
pinMode(3, OUTPUT);
pinMode(12, INPUT_PULLUP);
_bounseInputD12O = digitalRead(12);
}
void loop()
{
bool _bounceInputTmpD12 = (digitalRead (12));
if (_bounseInputD12S)
{
if (millis() >= (_bounseInputD12P + 40))
{
_bounseInputD12O= _bounceInputTmpD12;
_bounseInputD12S=0;
}
}
else
{
if (_bounceInputTmpD12 != _bounseInputD12O)
{
_bounseInputD12S=1;
_bounseInputD12P = millis();
}
}
//Плата:1
if (!(0))
{
if (! _gen1I)
{
_gen1I = 1;
_gen1O = 1;
_gen1P = millis();
}
}
else
{
_gen1I = 0 ;
_gen1O= 0;
}
if (_gen1I)
{
if (_isTimer (_gen1P , 25))
{
_gen1P = millis();
_gen1O = ! _gen1O;
}
}
if (!(_bounseInputD12O))
{
if (_trgrt1I)
{
_trgrt1 = 0;
}
else
{
_trgrt1 = 1;
_trgrt1I = 1;
}
}
else
{
_trgrt1 = 0;
_trgrt1I = 0;
}
;
if (_gen1O)
{
if (! _count1I)
{
_count1I = 1;
if (!(_bounseInputD12O))
{
if(_count1_Value < 1200)
{
_count1_Value = _count1_Value + 1;
}
}
else
{
if(_count1_Value > 0)
{
_count1_Value = _count1_Value - 1;
}
}
}
}
else
{
_count1I = 0;
}
if ((_trgrt1))
{
//Устанавливаем на пине частоту в режиме 0
PWM_frequency(3, (2000L), 0);
}
//изменить заполнение на пине
PWM_set (3, ((_poligon((_count1_Value), _Poligon_InArray_1, _Poligon_OutArray_1, 6))));
}
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));
}
}
int _poligon(int value, int intArray[], int outArray[], int arraySize)
{
struct _poligonInexes indexes;
indexes = _getPoligonIndexes(value, intArray, arraySize);
return map(value, intArray[indexes.minIndex], intArray[indexes.maxIndex], outArray[indexes.minIndex], outArray[indexes.maxIndex]);
}
struct _poligonInexes _getPoligonIndexes(int value, int array[], int arraySize)
{
struct _poligonInexes result;
int i;
result.minIndex = 0;
result.maxIndex = 0;
for (i = 0; i < arraySize; i++)
{
if (array [result.minIndex] > array[i])
{
result.minIndex = i;
}
if (array [result.maxIndex] < array[i])
{
result.maxIndex = i;
}
}
for (i = 0; i < arraySize; i++)
{
if ((array [i] >= value) && (array [result.maxIndex] > array[i]))
{
result.maxIndex = i;
}
}
if (result.maxIndex==0)
{
result.minIndex = 0;
result.maxIndex=1;
}
else
{
result.minIndex = result.maxIndex -1;
}
return result;
return result;
}
Вт июн 28, 2022 18:41:32
Ср июн 29, 2022 06:40:58
Ср июн 29, 2022 09:48:35
Ср июн 29, 2022 10:09:45