54 строки
1,9 КиБ
C
54 строки
1,9 КиБ
C
void initSvet();
|
|
void DvizhEst();
|
|
void DvizhaNet();
|
|
void PlavnoVklyuchit();
|
|
void PlavnoVyklyuchit();
|
|
bool Vklyucheno();
|
|
void Vklyuchit();
|
|
void Vyklyuchit();
|
|
void Yarkost(int i);
|
|
void Enable();
|
|
void Disable();
|
|
void TaskSveta();
|
|
void PropustitRaz();
|
|
|
|
|
|
const int MAX_YARKOST = 25; const int MIN_YARKOST = 15; const int VREMYA_VKL = 2000; const unsigned long VREMYA_SVETA = 10000; const int VREMYA_VYKL = 10000; const int DIFF_YARKOST = MAX_YARKOST-MIN_YARKOST; TickType_t loopBlockTime = pdMS_TO_TICKS(1000); TickType_t vyklYarkBlockTime = pdMS_TO_TICKS(VREMYA_VYKL/DIFF_YARKOST); int yarkost; unsigned long kogdaVyklyuchit; void initSvet() {
|
|
yarkost=MIN_YARKOST; kogdaVyklyuchit=0; Vyklyuchit();
|
|
}
|
|
void DvizhEst() {
|
|
kogdaVyklyuchit=millis()+VREMYA_SVETA; if (DEBUG) { Serial.println("Vkl svet"); } PlavnoVklyuchit();
|
|
}
|
|
void DvizhaNet() {
|
|
if (kogdaVyklyuchit>millis()) { return; } if (Vklyucheno()) { if (DEBUG) { Serial.println("Vykl"); } PlavnoVyklyuchit(); }
|
|
}
|
|
void PlavnoVklyuchit() {
|
|
Enable(); for(yarkost=yarkost; yarkost<=MAX_YARKOST; yarkost++) {Yarkost(yarkost); if (DEBUG) { Serial.println(yarkost); } delay(VREMYA_VKL/DIFF_YARKOST);} Vklyuchit();
|
|
}
|
|
void PlavnoVyklyuchit() {
|
|
int v; for(yarkost=yarkost; yarkost>=MIN_YARKOST; yarkost--) {Yarkost(yarkost); if (DEBUG) { Serial.println(yarkost); } v=ulTaskNotifyTake(0,vyklYarkBlockTime); if (v>0) { DvizhEst(); return; }} Vyklyuchit();
|
|
}
|
|
bool Vklyucheno() {
|
|
return yarkost>MIN_YARKOST;
|
|
}
|
|
void Vklyuchit() {
|
|
Yarkost(MAX_YARKOST); Enable();
|
|
}
|
|
void Vyklyuchit() {
|
|
Yarkost(MIN_YARKOST); Disable();
|
|
}
|
|
void Yarkost(int i) {
|
|
analogWrite(SVET_YARK_PIN,255-i);
|
|
}
|
|
void Enable() {
|
|
digitalWrite(SVET_ONOFF_PIN,1);
|
|
}
|
|
void Disable() {
|
|
digitalWrite(SVET_ONOFF_PIN,0);
|
|
}
|
|
void TaskSveta() {
|
|
int v; PropustitRaz(); while(1) {v=ulTaskNotifyTake(0,loopBlockTime); if (v>0) { DvizhEst(); } else { DvizhaNet(); }}
|
|
}
|
|
void PropustitRaz() {
|
|
ulTaskNotifyTake(0,loopBlockTime);
|
|
}
|