int MotorPWM = 10;
int MotorSpeed = 150; // vary this value between 0 and 500 for 9-bit precision whereby 500 = stop and 0 = full speed
void setup ()
{
TCCR1A = B11110010;
TCCR1B = B00010001;
ICR1 = 500 ; // 9 bit resolution, this value sets the frequency of the PWM-signal to 16kHz
OCR1B = 500; // vary this value between 0 (max power) and 500 (500 = off) for 9-bit precision - PWM at pin MotorPWM
pinMode(MotorPWM, OUTPUT); // declare the port as an OUTPUT OCR1A = 1023;
analogWrite(MotorPWM,MotorSpeed); //initialize primary pwm
}
void loop()
{
//тут идёт сама программ регулировки оборотов
char Key = K_pad.getKey();
if (Key =='1')
{
if (MotorSpeed > 0)
{
MotorSpeed = MotorSpeed -50;
if (MotorSpeed==450)
{
MotorSpeed = 300;
}
}
if (OCR1A <= 500) {OCR1A = MotorSpeed;}
if (OCR1B <= 500) {OCR1B = MotorSpeed;}
}
if (Key == '7')
{
if (MotorSpeed < 500)
{
MotorSpeed = MotorSpeed +50;
if (MotorSpeed == 350)
{
MotorSpeed = 500;
}
}
if (OCR1A <= 500) {OCR1A = MotorSpeed;}
if (OCR1B <= 500) {OCR1B = MotorSpeed;}
}
//но нужна защита от перегрева есть прикручен термо датчик, температура выводитсья
// теперь надо чтобы она и гасила мотор
if (T_motor > 65)
{
// вот тут чего то надо выключить но так, чтобы после тогоб как остынет мотор имел //разрешение на пуск. Т.э. нажал кнопку (любую) и он пошёл.
}
}


