Commit 9a4c562181306cd45c908095524d59ffd4ebea07

Authored by NabiyevTR
Committed by GitHub
1 parent 53b5d587

Update DALI.ino

Showing 1 changed file with 165 additions and 122 deletions
DALI.ino
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   -
  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 + dali.msgMode = true;
  25 + Serial.println(dali.analogLevel);
  26 + help(); //Show help
  27 +
  28 +}
  29 +
  30 +
  31 +void help() {
  32 + Serial.println("Enter 16 bit command or another command from list:");
  33 + Serial.println("help - command list");
  34 + Serial.println("on - broadcast on 100%");
  35 + Serial.println("off - broadcast off 0%");
  36 + Serial.println("scan - device short address scan");
  37 + Serial.println("initialise - start process of initialisation");
  38 + Serial.println();
  39 +}
  40 +
  41 +
  42 +void sinus () {
  43 + uint8_t lf_1_add = 0;
  44 + uint8_t lf_2_add = 1;
  45 + uint8_t lf_3_add = 2;
  46 + uint8_t lf_1;
  47 + uint8_t lf_2;
  48 + uint8_t lf_3;
  49 + int i;
  50 + int j = 0;
  51 +
  52 + while (Serial.available() == 0) {
  53 + for (i = 0; i < 360; i = i + 1) {
  54 +
  55 + if (Serial.available() != 0) {
  56 + dali.transmit(BROADCAST_C, ON_C);
  57 + break;
  58 + }
  59 +
  60 + lf_1 = (int) abs(254 * sin(i * 3.14 / 180));
  61 + lf_2 = (int) abs(254 * sin(i * 3.14 / 180 + 2 * 3.14 / 3));
  62 + lf_3 = (int) abs(254 * sin(i * 3.14 / 180 + 1 * 3.14 / 3));
  63 + dali.transmit(lf_1_add << 1, lf_1);
  64 + delay(5);
  65 + dali.transmit(lf_2_add << 1, lf_2);
  66 + delay(5);
  67 + dali.transmit(lf_3_add << 1, lf_3);
  68 + delay(5);
  69 + delay(20);
  70 + }
  71 + }
  72 +}
  73 +
  74 +
  75 +
  76 +void testReceive () {
  77 +
  78 +
  79 +
  80 + dali.transmit(0, 254);
  81 + delay(200);
  82 + dali.transmit(1, 0x90);
  83 + Serial.println(dali.receive());
  84 +
  85 +
  86 +
  87 +
  88 +}
  89 +
  90 +
  91 +
  92 +
  93 +
  94 +
  95 +
  96 +
  97 +
  98 +
  99 +
  100 +
  101 +
  102 +
  103 +void loop() {
  104 +
  105 + const int delaytime = 500;
  106 + int i;
  107 + int cmd1;
  108 + int cmd2;
  109 + String comMsg;
  110 +
  111 +
  112 + // Read command from port
  113 +
  114 + delay(delaytime);
  115 +
  116 + while (Serial.available()) {
  117 + comMsg = comMsg + (char)(Serial.read());
  118 + }; // read data from serial
  119 +
  120 + if (comMsg == "sinus") {
  121 + sinus();
  122 + };
  123 +
  124 + if (comMsg == "scan") {
  125 + dali.scanShortAdd();
  126 + }; // scan short addresses
  127 +
  128 + if (comMsg == "on") {
  129 + dali.transmit(BROADCAST_C, ON_C);
  130 + }; // broadcast, 100%
  131 +
  132 + if (comMsg == "off") {
  133 + dali.transmit(BROADCAST_C, OFF_C);
  134 + }; // broadcast, 0%
  135 +
  136 + if (comMsg == "initialise" or comMsg == "ini") {
  137 + dali.initialisation();
  138 + }; // initialisation
  139 +
  140 + if (comMsg == "help") {
  141 + help();
  142 + }; //help
  143 +
  144 + if (comMsg == "test") {
  145 + testReceive();
  146 + }; //graph
  147 +
  148 +
  149 +
  150 + if (dali.cmdCheck(comMsg, cmd1, cmd2)) {
  151 + dali.transmit(cmd1, cmd2); // command in binary format: (address byte, command byte)
  152 + }
  153 + delay(delaytime);
  154 +
  155 +};
  156 +
  157 +
  158 +
  159 +
  160 +
  161 +
  162 +
  163 +
  164 +
  165 +
123 166  
... ...