You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learn/01.starting-guide/00.getting-started-arduino/getting-started-arduino.md
+19-16Lines changed: 19 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -190,10 +190,10 @@ To control actuators, it is common to use `digitalWrite()` and `analogWrite()`.
190
190
191
191
```arduino
192
192
digitalWrite(LED, HIGH); //turn on an LED
193
-
digitalWrite(LED, LOW); //turn off an LED
193
+
digitalWrite(LED, LOW); //turn off an LED
194
194
195
195
analogWrite(motor, 255); //set a motor to maximum capacity
196
-
analogWrite(motor, 25); //set a motor to 10% of its capacity
196
+
analogWrite(motor, 25); //set a motor to 10% of its capacity
197
197
```
198
198
199
199
#### Input & Output
@@ -203,13 +203,12 @@ Sensors and actuators, are typically referred to as **inputs and outputs**. When
203
203
A basic example of this is a **button** and an **LED**. We can write a conditional that checks if a button is pressed, turn on the LED, and turn it off if the button is not pressed. In an Arduino program, it looks like this:
204
204
205
205
```arduino
206
-
int buttonState = digitalRead(buttonPin); //read and store the button state (0 or 1)
206
+
int buttonState = digitalRead(buttonPin); //read and store the button state (0 or 1)
207
207
208
-
if(buttonState == HIGH){ //check if state is high (button is pressed)
209
-
digitalWrite(LED, HIGH) //turn on LED
210
-
}
211
-
else {
212
-
digitalWrite(LED, LOW); //turn off LED
208
+
if(buttonState == HIGH){ //check if state is high (button is pressed)
209
+
digitalWrite(LED, HIGH); //turn on LED
210
+
} else {
211
+
digitalWrite(LED, LOW); //turn off LED
213
212
}
214
213
```
215
214
@@ -523,11 +522,13 @@ unsigned long currentMillis = millis();
523
522
524
523
//conditional that checks whether 1 second has passed since last event
525
524
if (currentMillis - previousMillis_1 >= interval_1) {
525
+
previousMillis_1 = millis();
526
526
//execute a piece of code, every *1 second*
527
527
}
528
528
529
529
//conditional that checks whether 2 seconds have passed since last event
530
530
if (currentMillis - previousMillis_2 >= interval_2) {
531
+
previousMillis_2 = millis();
531
532
//execute a piece of code, every *2 seconds*
532
533
}
533
534
@@ -607,7 +608,7 @@ float
607
608
int
608
609
long
609
610
short
610
-
String()
611
+
String
611
612
```
612
613
613
614
To store data in for example an `int` (integer):
@@ -631,7 +632,7 @@ String exampleSentence = "This is a string!";
631
632
For simple switches and true/false, we use booleans:
632
633
633
634
```arduino
634
-
bool exampleSwitch = true/false;
635
+
bool exampleSwitch = true; // true/false
635
636
```
636
637
637
638
### Serial Communication
@@ -754,10 +755,10 @@ while (variable == true) {
754
755
}
755
756
```
756
757
757
-
A basic use of a `for` loop is to execute a block of code a number of times (in this case, 10).
758
+
A basic use of a `for` loop is to execute a block of code a custom number of times (in this case, 10).
758
759
759
760
```arduino
760
-
for (int x = 0; x <= 10; x++) {
761
+
for (int x = 0; x < 10; x++) {
761
762
//do something 10 times
762
763
}
763
764
```
@@ -810,29 +811,31 @@ if(value > 10) {
810
811
811
812
#### Boolean Operators
812
813
813
-
Boolean operators (logical not`!`, and`&&`, or`||`) can for example be used for more advanced conditionals.
814
+
Boolean operators (logical NOT`!`, AND`&&` and OR`||`) can for example be used for more advanced conditionals.
814
815
815
-
To use the and`&&` operator:
816
+
To use the AND`&&` operator:
816
817
817
818
```arduino
818
819
if(value > 10 && otherValue > 10){
819
820
//do something if only if *both* conditions are met
820
821
}
821
822
```
822
823
823
-
To use the or`||` operator:
824
+
To use the OR`||` operator:
824
825
825
826
```arduino
826
827
if(value > 10 || otherValue > 10){
827
828
//do something if a one *or* the other condition is met
0 commit comments