Commit ec2c85868535ff2282e03bd813064f56949ed194

Authored by NabiyevTR
Committed by GitHub
1 parent 8c015358

Add files via upload

Showing 1 changed file with 123 additions and 0 deletions
DALI.ino 0 → 100644
  1 +#include <Dali.h>
  2 +
  3 +
  4 +const int DALI_TX = 3;
  5 +const int DALI_RX_A = 0;
  6 +
  7 +
  8 +
  9 +#define BROADCAST_DP 0b11111110
  10 +#define BROADCAST_C 0b11111111
  11 +#define ON_DP 0b11111110
  12 +#define OFF_DP 0b00000000
  13 +#define ON_C 0b00000101
  14 +#define OFF_C 0b00000000
  15 +# define QUERY_STATUS 0b10010000
  16 +# define RESET 0b00100000
  17 +
  18 +void setup() {
  19 +
  20 + Serial.begin(74880);
  21 + dali.setupTransmit(DALI_TX);
  22 + dali.setupAnalogReceive(DALI_RX_A);
  23 + dali.busTest();
  24 + help(); //Show help
  25 +
  26 +}
  27 +
  28 +
  29 +void help() {
  30 + Serial.println("Enter 16 bit command or another command from list:");
  31 + Serial.println("help - command list");
  32 + Serial.println("on - broadcast on 100%");
  33 + Serial.println("off - broadcast off 0%");
  34 + Serial.println("scan - device short address scan");
  35 + Serial.println("initialise - start process of initialisation");
  36 + Serial.println();
  37 +}
  38 +
  39 +
  40 +void sinus () {
  41 + uint8_t lf_1_add = 0;
  42 + uint8_t lf_2_add = 1;
  43 + uint8_t lf_3_add = 2;
  44 + uint8_t lf_1;
  45 + uint8_t lf_2;
  46 + uint8_t lf_3;
  47 + int i;
  48 + int j = 0;
  49 +
  50 + while (j != 1) {
  51 + for (i = 0; i < 360; i = i + 1) {
  52 + lf_1 = (int) abs(254 * sin(i * 3.14 / 180));
  53 + lf_2 = (int) abs(254 * sin(i * 3.14 / 180 + 2 * 3.14 / 3));
  54 + lf_3 = (int) abs(254 * sin(i * 3.14 / 180 + 1 * 3.14 / 3));
  55 + dali.transmit(lf_1_add << 1, lf_1);
  56 + delay(5);
  57 + dali.transmit(lf_2_add << 1, lf_2);
  58 + delay(5);
  59 + dali.transmit(lf_3_add << 1, lf_3);
  60 + delay(5);
  61 + delay(20);
  62 + }
  63 + }
  64 +}
  65 +
  66 +void loop() {
  67 +
  68 + const int delaytime = 500;
  69 + int i;
  70 + int cmd1;
  71 + int cmd2;
  72 + String comMsg;
  73 +
  74 +
  75 + // Read command from port
  76 +
  77 + delay(delaytime);
  78 +
  79 + while (Serial.available()) {
  80 + comMsg = comMsg + (char)(Serial.read());
  81 + }; // read data from serial
  82 +
  83 + if (comMsg == "sinus") {
  84 + sinus();
  85 + };
  86 +
  87 + if (comMsg == "scan") {
  88 + dali.scanShortAdd();
  89 + }; // scan short addresses
  90 +
  91 + if (comMsg == "on") {
  92 + dali.transmit(BROADCAST_C, ON_C);
  93 + }; // broadcast, 100%
  94 +
  95 + if (comMsg == "off") {
  96 + dali.transmit(BROADCAST_C, OFF_C);
  97 + }; // broadcast, 0%
  98 +
  99 + if (comMsg == "initialise" or comMsg == "ini") {
  100 + dali.initialisation();
  101 + }; // initialisation
  102 +
  103 + if (comMsg == "help") {
  104 + help();
  105 + }; //help
  106 +
  107 +if (dali.cmdCheck(comMsg, cmd1, cmd2)) {
  108 + dali.transmit(cmd1, cmd2); // command in binary format: (address byte, command byte)
  109 +}
  110 + delay(delaytime);
  111 +
  112 +};
  113 +
  114 +
  115 +
  116 +
  117 +
  118 +
  119 +
  120 +
  121 +
  122 +
  123 +
... ...