50 строки
1,7 КиБ
C
50 строки
1,7 КиБ
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();
|
|
|
|
|
|
const int MAX_YARKOST = 100; const int MIN_YARKOST = 0; const unsigned long VREMYA_SVETA = 20000; TickType_t loopBlockTime = pdMS_TO_TICKS(1000); int vklYarkBlockTime = 10; TickType_t vyklYarkBlockTime = pdMS_TO_TICKS(50); int yarkost; unsigned long kogdaVyklyuchit; void initSvet() {
|
|
yarkost=0; kogdaVyklyuchit=0; Vyklyuchit();
|
|
}
|
|
void DvizhEst() {
|
|
kogdaVyklyuchit=millis()+VREMYA_SVETA; if (!Vklyucheno()) { 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(vklYarkBlockTime);} 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>0;
|
|
}
|
|
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; while(1) {v=ulTaskNotifyTake(0,loopBlockTime); if (v>0) { DvizhEst(); } else { DvizhaNet(); }}
|
|
}
|