Advertisement
krzysp

grzałka virtuino IoT blok z programem

Jan 10th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 2.67 KB | Source Code | 0 0
  1. #define przek   0
  2. #define led_wew 2
  3.  
  4. bool sendValue(const char* tag, String value);
  5.  
  6. int V1_Value = 0;
  7. int V2_Value = 0;
  8. int V3_Value = 0;
  9. int V4_Value = 0;
  10.  
  11. int t_on = 10;
  12. int t_off = 10;
  13. int stan_przek = 1;  //0 włączony 1 wyłączony 2 regulowany czas załączenia
  14.  
  15.  
  16. void speed_led() {
  17.   if (stan_przek == 1) akcja.updateInterval(0, 2000);
  18.   if (stan_przek == 0) akcja.updateInterval(0, 1000);
  19.   if (stan_przek == 2) akcja.updateInterval(0, 500);
  20. }
  21.  
  22. void wys_t() {
  23.  
  24.   sendValue(pin7, String(t_on));
  25.   pin7_lastValue = t_on;
  26.   sendValue(pin8, String(t_off));
  27.   pin8_lastValue = t_off;
  28. }
  29. int on_off = 0;    // stan włącznika głównego
  30. int on_off_t = 0;  // stan włącznika regulacji czasu
  31.  
  32. void pin1_rec(String value_Text) {
  33.   V1_Value = value_Text.toInt();
  34.   if (V1_Value) on_off = 1;  else on_off = 0;
  35.  
  36.   if (on_off) {
  37.     if (on_off_t) stan_przek = 2;  else stan_przek = 0;
  38.   } else stan_przek = 1;
  39.  
  40.   digitalWrite(przek, V1_Value);
  41.   sendValue(pin6, String(stan_przek));
  42.   pin6_lastValue = stan_przek;
  43.   wys_t();
  44.   speed_led();
  45. }
  46.  
  47. int t_on_mem = 10;
  48. int t_off_mem = 10;
  49.  
  50. void pin2_rec(String value_Text) {
  51.   V2_Value = value_Text.toInt();
  52.   // Serial.println("V2=" + value_Text);
  53.  
  54.   on_off_t = V2_Value;
  55.   if (on_off_t) t_on = t_on_mem;
  56.   // else t_on = 0;
  57.   if (on_off_t) t_off = t_off_mem;
  58.   // else t_off = 0;
  59.   if (on_off_t)
  60.     ;
  61.   else stan_przek = !on_off;
  62.   sendValue(pin6, String(stan_przek));
  63.   pin6_lastValue = stan_przek;
  64.   wys_t();
  65. }
  66.  
  67. void pin3_rec(String value_Text) {
  68.   V3_Value = value_Text.toInt();
  69.   t_on_mem = V3_Value;
  70.   t_on = t_on_mem;
  71.   wys_t();
  72.  
  73.   //Serial.println("V3=" + value_Text);
  74. }
  75.  
  76. void pin4_rec(String value_Text) {
  77.   V4_Value = value_Text.toInt();
  78.   t_off_mem = V4_Value;
  79.   t_off = t_off_mem;
  80.   wys_t();
  81.  
  82.   // Serial.println("V4=" + value_Text);
  83. }
  84.  
  85.  
  86. void p_setup()
  87. {
  88.   pinMode(led_wew, OUTPUT);   //LED na module
  89.   digitalWrite(led_wew, HIGH);
  90.   pinMode(przek, OUTPUT); //pin przekaźnika
  91.   digitalWrite(przek, HIGH);
  92. }
  93.  
  94. int a = 0;
  95. int b = 0;
  96. void LED_timer() {
  97.   a = !a;
  98.   digitalWrite(led_wew, a);
  99.   sendValue(pin0, String(b));  //led in virtuino
  100.   pin0_lastValue = b;
  101.   b = !b;
  102. }
  103.  
  104. void czas_timer() {
  105.   if (stan_przek > 1) {
  106.     if (stan_przek == 2) {
  107.       t_on = t_on - 1;
  108.       if (t_on < 1) {
  109.         t_off = t_off_mem + 1;
  110.         digitalWrite(przek, HIGH);
  111.         stan_przek = 3;
  112.       }
  113.     }
  114.     if (stan_przek == 3) {
  115.       t_off = t_off - 1;
  116.       if (t_off < 1) {
  117.         t_on = t_on_mem;
  118.         digitalWrite(przek, LOW);
  119.         stan_przek = 2;
  120.       }
  121.     }
  122.   }
  123.   wys_t();
  124. }
  125.  
  126.  
  127. void  program_grzalka()
  128. {
  129.   //my program tu akurat nic nie ma
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement