Skip to content

Learn, Getting Started: fix typos [PC-916] #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ To control actuators, it is common to use `digitalWrite()` and `analogWrite()`.

```arduino
digitalWrite(LED, HIGH); //turn on an LED
digitalWrite(LED, LOW); //turn off an LED
digitalWrite(LED, LOW); //turn off an LED

analogWrite(motor, 255); //set a motor to maximum capacity
analogWrite(motor, 25); //set a motor to 10% of its capacity
analogWrite(motor, 25); //set a motor to 10% of its capacity
```

#### Input & Output
Expand All @@ -203,13 +203,12 @@ Sensors and actuators, are typically referred to as **inputs and outputs**. When
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:

```arduino
int buttonState = digitalRead(buttonPin); //read and store the button state (0 or 1)
int buttonState = digitalRead(buttonPin); //read and store the button state (0 or 1)

if(buttonState == HIGH){ //check if state is high (button is pressed)
digitalWrite(LED, HIGH) //turn on LED
}
else {
digitalWrite(LED, LOW); //turn off LED
if(buttonState == HIGH){ //check if state is high (button is pressed)
digitalWrite(LED, HIGH); //turn on LED
} else {
digitalWrite(LED, LOW); //turn off LED
}
```

Expand Down Expand Up @@ -523,11 +522,13 @@ unsigned long currentMillis = millis();

//conditional that checks whether 1 second has passed since last event
if (currentMillis - previousMillis_1 >= interval_1) {
previousMillis_1 = millis();
//execute a piece of code, every *1 second*
}

//conditional that checks whether 2 seconds have passed since last event
if (currentMillis - previousMillis_2 >= interval_2) {
previousMillis_2 = millis();
//execute a piece of code, every *2 seconds*
}

Expand Down Expand Up @@ -607,7 +608,7 @@ float
int
long
short
String()
String
```

To store data in for example an `int` (integer):
Expand All @@ -631,7 +632,7 @@ String exampleSentence = "This is a string!";
For simple switches and true/false, we use booleans:

```arduino
bool exampleSwitch = true/false;
bool exampleSwitch = true; // true/false
```

### Serial Communication
Expand Down Expand Up @@ -754,10 +755,10 @@ while (variable == true) {
}
```

A basic use of a `for` loop is to execute a block of code a number of times (in this case, 10).
A basic use of a `for` loop is to execute a block of code a custom number of times (in this case, 10).

```arduino
for (int x = 0; x <= 10; x++) {
for (int x = 0; x < 10; x++) {
//do something 10 times
}
```
Expand Down Expand Up @@ -810,29 +811,31 @@ if(value > 10) {

#### Boolean Operators

Boolean operators (logical not `!`, and `&&`, or `||`) can for example be used for more advanced conditionals.
Boolean operators (logical NOT `!`, AND `&&` and OR `||`) can for example be used for more advanced conditionals.

To use the and `&&` operator:
To use the AND `&&` operator:

```arduino
if(value > 10 && otherValue > 10){
//do something if only if *both* conditions are met
}
```

To use the or `||` operator:
To use the OR `||` operator:

```arduino
if(value > 10 || otherValue > 10){
//do something if a one *or* the other condition is met
}
```

To use the not `!` operator:
To use the NOT `!` operator:

```arduino
if(!value){
//do something if value is false (!)
}
```

#### Compound Operators

Expand Down