Skip to content
Snippets Groups Projects
Commit 0e55667b authored by Rodrigo Shiordia López's avatar Rodrigo Shiordia López
Browse files

Update recitation/programming/slides.html

parent 20d70ba4
No related branches found
No related tags found
No related merge requests found
Pipeline #376850 passed
......@@ -240,8 +240,95 @@ void loop() {
* Functions and methods are ways of reusing code.
* Something that you are going to do several times, you can put inside a function and use it again and again.
* A function normally has a return value: somehting that it returns back to you after you call or invoke it. (Some functions have no return value or a void return value.)
* It's important to distinguish between Built-in functions and custom functions.
---
# Functions: return value
```Arduino
//Explaining Functions and methods
//Rodrigo Shiordia 2023
void setup() {
Serial.begin(9600);
Serial.println(" Temperature Calculator ");
}
void loop() {
Serial.print("Please enter temperature in Fahrenheit: ");
while (Serial.available() == 0) {
}
float F = Serial.parseFloat();
float C = fahrenheitToCelsius(F);
Serial.print("Temperature in Celsius: ");
Serial.println(C);
}
float fahrenheitToCelsius(float theValue) {
return (theValue -32)*0.5556;
}
```
---
# Functions: void return
```Arduino
//Explaining Functions and methods
//Rodrigo Shiordia 2023
int ledPin = 1;
void setup() {
Serial.begin(9600);
Serial.println(" Function based LED blinker! ");
}
void loop() {
Serial.print("How Many times you want the LED to blink: ");
while (Serial.available() == 0) {
}
int T = Serial.parseInt();
blinkLED(T);
}
void blinkLED(int times) {
for (int i = 0; i < times; i++) {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
}
```
---
# Debugging
* Debugging is about getting your code to do what you want.
* Syntax errors are when your code is written incorrectly according to the programming language. In C/Arduino, the most common is missing a semicolon or a bracket.
* Use checks and print statements to know exaclty what your code is doing at any time.
---
# Libraries
* Arduino has libraries that extend its capabilities.
* Libraries are collections of code that you can use. They normally provide you with functions and methods for you to use.
---
# Tips for writing programs
* Always start with some idea of what you want to do.
* Write pseudocode.
* Write small blocks of code and run and upload so you know it's working before writing more code.
* Read as much code as you can. Writing code requires you to understand code.
* Use online resources:
* [stackOverflow](https://stackoverflow.com/)
* [Arduino Forums](https://forum.arduino.cc/)
---
</textarea>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment