Advertisement
pokornymartin

callback_schody

May 4th, 2021
3,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. void callback(char* topic, byte* payload, unsigned int length) {
  2.  
  3.   String topicStr = topic;
  4.  
  5.    if (topicStr == "domek/schodiste/set/")
  6.     {
  7.  
  8.       // Deserializace JSON
  9.       DeserializationError error = deserializeJson(doc, payload);
  10.  
  11.       if (error) {
  12.         Serial.print(F("deserializeJson() failed: "));
  13.         Serial.println(error.f_str());
  14.         return;
  15.       }
  16.  
  17.   int smer = doc["smer"];
  18.   int rychlost = doc["rychlost"];
  19.   int cas = doc["cas"];
  20.   int intenzita = doc["intenzita"];
  21.   Serial.print("Směr: ");
  22.   Serial.println(smer);
  23.   Serial.print("Rychlost: ");
  24.   Serial.println(rychlost);
  25.   Serial.print("Doba svitu: ");
  26.   Serial.println(cas);
  27.  
  28. int schod=0;
  29. if (smer==1){ //smer zespoda nahoru
  30.  
  31.       for (int i = 0; i < 15; i++) { //rozsvitit
  32.         schod=i+1;
  33.         if (int(doc["schody"][i])==1){
  34.           rozsvit(schod,intenzita);
  35.           delay (rychlost);
  36.         }
  37.  
  38.       }
  39.  
  40.     delay (cas); //doba svitu
  41.  
  42.       for (int i = 0; i < 15; ++i) { //zhasnout
  43.         schod=i+1;
  44.         zhasni(schod);
  45.           delay (rychlost);
  46.       }
  47.  
  48.  }else if (smer==2){ //smer zhora dolu
  49.  
  50.       for (int j = 14; j > -1; j--) {//rozsvitit
  51.         schod=j+1;
  52.         if (int(doc["schody"][j])==1){
  53.           rozsvit(schod,intenzita);
  54.           delay (rychlost);
  55.         }
  56.       }
  57.  
  58.     delay (cas); //doba svitu
  59.  
  60.       for (int j = 14; j > -1; j--) {//zhasnout
  61.         schod=j+1;
  62.         zhasni(schod);
  63.           delay (rychlost);
  64.       }
  65.  
  66.  }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement