Skip to content

Commit 2d721b8

Browse files
authored
Getting started, revert sketch changes (#253)
1 parent 50a81c7 commit 2d721b8

File tree

1 file changed

+89
-49
lines changed
  • content/hardware/05.pro-solutions/solutions-and-kits/opta/tutorials/getting-started

1 file changed

+89
-49
lines changed

content/hardware/05.pro-solutions/solutions-and-kits/opta/tutorials/getting-started/content.md

Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,33 @@ Copy the sketch below into the Arduino IDE sketch editor, then upload it to Opta
6969
When the sketch is uploaded you will see the Opta's STATUS LEDs blinking in sequence.
7070

7171
```arduino
72-
int leds[] = {LED_D0, LED_D1, LED_D2, LED_D3};
73-
7472
void setup() {
75-
for (int i = 0 ; i < 4 ; i++){
76-
pinMode(leds[i], OUTPUT);
77-
}
73+
pinMode(LED_D0, OUTPUT);
74+
pinMode(LED_D1, OUTPUT);
75+
pinMode(LED_D2, OUTPUT);
76+
pinMode(LED_D3, OUTPUT);
7877
}
7978
8079
void loop() {
81-
for (int i = 0 ; i < 4 ; i++){
82-
digitalWrite(leds[i], HIGH);
83-
delay(100);
84-
digitalWrite(leds[i], LOW);
85-
delay(100);
86-
}
80+
digitalWrite(LED_D0, HIGH);
81+
delay(100);
82+
digitalWrite(LED_D0, LOW);
83+
delay(100);
84+
85+
digitalWrite(LED_D1, HIGH);
86+
delay(100);
87+
digitalWrite(LED_D1, LOW);
88+
delay(100);
89+
90+
digitalWrite(LED_D2, HIGH);
91+
delay(100);
92+
digitalWrite(LED_D2, LOW);
93+
delay(100);
94+
95+
digitalWrite(LED_D3, HIGH);
96+
delay(100);
97+
digitalWrite(LED_D3, LOW);
98+
delay(500);
8799
}
88100
```
89101

@@ -99,14 +111,12 @@ The button is defined in the core as `BTN_USER`: 'HIGH' as default (not pressed)
99111
int buttonState = 0;
100112
int counter = 0;
101113
102-
int leds[] = {LED_D0, LED_D1, LED_D2, LED_D3};
103-
104114
void setup() {
105-
// Initialize Opta LEDs
106-
for (int i = 0 ; i < 4 ; i++){
107-
pinMode(leds[i], OUTPUT);
108-
}
109-
115+
// Initialize OPTA LEDs
116+
pinMode(LED_D0, OUTPUT);
117+
pinMode(LED_D1, OUTPUT);
118+
pinMode(LED_D2, OUTPUT);
119+
pinMode(LED_D3, OUTPUT);
110120
pinMode(BTN_USER, INPUT);
111121
}
112122
@@ -126,16 +136,26 @@ void loop() {
126136
}
127137
128138
void changeLights() {
129-
// Turn off the LEDs
130-
for (int i = 0 ; i < 4 ; i++){
131-
digitalWrite(leds[i], OUTPUT);
139+
switch(counter){
140+
case 0:
141+
digitalWrite(LED_D0, LOW);
142+
digitalWrite(LED_D1, LOW);
143+
digitalWrite(LED_D2, LOW);
144+
digitalWrite(LED_D3, LOW);
145+
break;
146+
case 1:
147+
digitalWrite(LED_D0, HIGH);
148+
break;
149+
case 2:
150+
digitalWrite(LED_D1, HIGH);
151+
break;
152+
case 3:
153+
digitalWrite(LED_D2, HIGH);
154+
break;
155+
case 4:
156+
digitalWrite(LED_D3, HIGH);
157+
break;
132158
}
133-
134-
// Turn on X length of LEDs
135-
for (int i = 0 ; i < counter ; i++){
136-
digitalWrite(leds[i], HIGH);
137-
}
138-
139159
delay(100);
140160
}
141161
```
@@ -186,32 +206,52 @@ Opta™ has dedicated terminals for power supply located in the upper part of Op
186206
The entire sketch can be found below, copy it into your IDE and upload it to your device.
187207

188208
```arduino
189-
int relays[] = {RELAY1, RELAY2, RELAY3, RELAY4};
190-
int leds[] = {LED_D0, LED_D1, LED_D2, LED_D3};
191-
192209
void setup() {
193-
for (int i = 0; i < 4; i++){
194-
// Initialize Relays outputs
195-
pinMode(relays[i], OUTPUT);
196-
197-
// Initialize Opta LEDs
198-
pinMode(leds[i], OUTPUT);
199-
}
210+
// Initialize Relays outputs
211+
pinMode(D0, OUTPUT);
212+
pinMode(D1, OUTPUT);
213+
pinMode(D2, OUTPUT);
214+
pinMode(D3, OUTPUT);
215+
216+
// Initialize Opta LEDs
217+
pinMode(LED_D0, OUTPUT);
218+
pinMode(LED_D1, OUTPUT);
219+
pinMode(LED_D2, OUTPUT);
220+
pinMode(LED_D3, OUTPUT);
200221
}
201222
202223
void loop() {
203-
// Closes and opens the contacts of each relay and sync it with each LED
204-
for (int = 0; i < 4; i++){
205-
// Relay Closed, LED ON
206-
digitalWrite(relays[i], HIGH);
207-
digitalWrite(leds[i], HIGH);
208-
delay(1000);
209-
210-
// Relay Open, LED OFF
211-
digitalWrite(relays[i], LOW);
212-
digitalWrite(leds[i], LOW);
213-
delay(1000);
214-
}
224+
// Closes and opens the contact of relay 1 and turns on led 1
225+
digitalWrite(D0, HIGH); // Sets the relay 1 on
226+
digitalWrite(LED_D0, HIGH);
227+
delay(1000);
228+
digitalWrite(D0, LOW); // Sets the relay 1 off
229+
digitalWrite(LED_D0, LOW);
230+
delay(1000);
231+
232+
// Closes and opens the contact of relay 2 and turns on led 2
233+
digitalWrite(D1, HIGH); // Sets the relay 2 on
234+
digitalWrite(LED_D1, HIGH);
235+
delay(1000);
236+
digitalWrite(D1, LOW); // Sets the relay 2 off
237+
digitalWrite(LED_D1, LOW);
238+
delay(1000);
239+
240+
// Closes and opens the contact of relay 3 and turns on led 3
241+
digitalWrite(D2, HIGH); // Sets the relay 3 on
242+
digitalWrite(LED_D2, HIGH);
243+
delay(1000);
244+
digitalWrite(D2, LOW); // Sets the relay 3 off
245+
digitalWrite(LED_D2, LOW);
246+
delay(1000);
247+
248+
// Closes and opens the contact of relay 4 and turns on led 4
249+
digitalWrite(D3, HIGH); // Sets the relay 4 on
250+
digitalWrite(LED_D3, HIGH);
251+
delay(1000);
252+
digitalWrite(D3, LOW); // Sets the relay 4 off
253+
digitalWrite(LED_D3, LOW);
254+
delay(1000);
215255
}
216256
```
217257

0 commit comments

Comments
 (0)