Advertisement
dianartanto

Program kontrol 4 relay terjadwal dan sekaligus ON/OFF

Nov 16th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 3.02 KB | Source Code | 0 0
  1. #include "arduino_secrets.h"
  2. #include "thingProperties.h"
  3. String out = "Terjadwal:";
  4. String outa = "0";
  5. String outb = "0";
  6. String outc = "0";
  7. String outd = "0";
  8. bool terjadwal = true;
  9. void setup() {
  10.   pinMode(D1, OUTPUT);
  11.   pinMode(D2, OUTPUT);
  12.   pinMode(D3, OUTPUT);
  13.   pinMode(D4, OUTPUT);
  14.   pinMode(D5, OUTPUT);
  15.   pinMode(D6, OUTPUT);
  16.   pinMode(D7, OUTPUT);
  17.   pinMode(D8, OUTPUT);
  18.   digitalWrite(D1, HIGH);
  19.   digitalWrite(D2, HIGH);
  20.   digitalWrite(D3, HIGH);
  21.   digitalWrite(D4, HIGH);
  22.   digitalWrite(D5, HIGH);
  23.   digitalWrite(D6, HIGH);
  24.   digitalWrite(D7, HIGH);
  25.   digitalWrite(D8, HIGH);
  26.   Serial.begin(9600);
  27.   delay(1500);
  28.   initProperties();
  29.   ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  30.   setDebugMessageLevel(2);
  31.   ArduinoCloud.printDebugInfo();
  32. }
  33. void loop() {
  34.   ArduinoCloud.update();
  35.   if (a.isActive()) {
  36.     if (terjadwal) {
  37.       digitalWrite(D1, LOW);
  38.       outa = "1";
  39.     }
  40.   } else {
  41.     if (terjadwal) {
  42.       digitalWrite(D1, HIGH);
  43.       outa = "0";
  44.     }
  45.   }
  46.   if (b.isActive()) {
  47.     if (terjadwal) {
  48.       digitalWrite(D2, LOW);
  49.       outb = "1";
  50.     }
  51.   } else {
  52.     if (terjadwal) {
  53.       digitalWrite(D2, HIGH);
  54.       outb = "0";
  55.     }
  56.   }
  57.   if (c.isActive()) {
  58.     if (terjadwal) {
  59.       digitalWrite(D3, LOW);
  60.       outc = "1";
  61.     }
  62.   } else {
  63.     if (terjadwal) {
  64.       digitalWrite(D3, HIGH);
  65.       outc = "0";
  66.     }
  67.   }
  68.   if (d.isActive()) {
  69.     if (terjadwal) {
  70.       digitalWrite(D4, LOW);
  71.       outd = "1";
  72.     }
  73.   } else {
  74.     if (terjadwal) {
  75.       digitalWrite(D4, HIGH);
  76.       outd = "0";
  77.     }
  78.   }
  79.   out1 = out + outa + "." + outb + "." + outc + "." + outd;
  80. }
  81. void onAChange() {
  82. }
  83. void onBChange() {
  84. }
  85. void onCChange() {
  86. }
  87. void onDChange() {
  88. }
  89. void onOut1Change() {
  90.   if (out1 == "T" || out1 == "t") {
  91.     terjadwal = true;
  92.     out = "Terjadwal:";
  93.   }
  94.   if (out1 == "M" || out1 == "m") {
  95.     terjadwal = false;
  96.     out = "Manual:";
  97.   }
  98.   if (!terjadwal) {
  99.     if (out1 == "A1" || out1 == "a1" || out2 == "V" || out2 == "v") {
  100.       digitalWrite(D1, LOW);
  101.       outa = "1";
  102.     }
  103.     if (out1 == "A0" || out1 == "a0" || out2 == "X" || out2 == "x") {
  104.       digitalWrite(D1, HIGH);
  105.       outa = "0";
  106.     }
  107.     if (out1 == "B1" || out1 == "b1" || out2 == "V" || out2 == "v") {
  108.       digitalWrite(D2, LOW);
  109.       outb = "1";
  110.     }
  111.     if (out1 == "B0" || out1 == "b0" || out2 == "X" || out2 == "x") {
  112.       digitalWrite(D2, HIGH);
  113.       outb = "0";
  114.     }
  115.     if (out1 == "C1" || out1 == "c1" || out2 == "V" || out2 == "v") {
  116.       digitalWrite(D3, LOW);
  117.       outc = "1";
  118.     }
  119.     if (out1 == "C0" || out1 == "c0" || out2 == "X" || out2 == "x") {
  120.       digitalWrite(D3, HIGH);
  121.       outc = "0";
  122.     }
  123.     if (out1 == "D1" || out1 == "d1" || out2 == "V" || out2 == "v") {
  124.       digitalWrite(D4, LOW);
  125.       outd = "1";
  126.     }
  127.     if (out1 == "D0" || out1 == "d0" || out2 == "X" || out2 == "x") {
  128.       digitalWrite(D4, HIGH);
  129.       outd = "0";
  130.     }
  131.   }
  132.   out1 = out + outa + "." + outb + "." + outc + "." + outd;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement