SlideShare a Scribd company logo
1 of 18
PROJECT: Arduino
II.
Proměnné
int pin = 13;
int pauza = 1000;
void setup() {
pinMode(pin, OUTPUT);
}
void loop() {
digitalWrite(pin, HIGH);
delay(pauza);
digitalWrite(pin, LOW);
delay(pauza);
}
PROJECT: Arduino MakersLAB / Paralelní
Polis // Milan "Sodomák" Půlkrábek
Typy proměnných
typ velikost rozsah
signed unsigned
char 8 b −128 až 127 0 až 255
int 16 b −32768 až 32767 0 až 65535
long 32 b
−2147483648
až 2147483647
0 až 4294967295
boolean 8 b true nebo false
PROJECT: Arduino MakersLAB / Paralelní
Polis // Milan "Sodomák" Půlkrábek
typ velikost rozsah
float 32 b 3,4x1038 až 3,4x1038
double 64 b −1,7x10308 až 1,7x10308
ASCII tabulka
PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek
Logické:
• false – hodnota 0
• true – nejen 1, ale jakékoliv nenulové číslo
Typ digitálního pinu:
• OUTPUT – nastaví pin jako výstup (40mA)
• INPUT – nastaví pin jako vstup
• INPUT_PULLUP – jako INPUT, ale výchozí hodnota je HIGH (vnitřní rezistor
připojen na +5V)
Hodnoty napětí na pinu:
• HIGH – 5V při výstupu, při vstupu pokud je větší než 3V
• LOW – 0V při výstupu, při vstupu pokud je menší než 2V
Vlastní:
#define NÁZEV hodnota // bez středníku nebo
const typ NÁZEV = hodnota;
Konstanty
Konstanty
#define LED 13
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
Podmínka „if“
Syntaxe:
if (podmínka) {
příkazy... ;
} else {
příkazy... ;
}
}
PROJECT: Arduino MakersLAB / Paralelní
Polis // Milan "Sodomák" Půlkrábek
Operátory podmínek
Operátor Kompletní zápis Význam
== x == y pokud se x rovná y
!= x != y pokud se x nerovná y
< x < y pokud je x menší než y
> x > y pokud je x větší než y
<= x <= y pokud je x menší nebo rovno y
>= x >= y pokud je x větší nebo rovno y
PROJECT: Arduino MakersLAB / Paralelní
Polis // Milan "Sodomák" Půlkrábek
Kombinování podmínek:
&& → logický součin (AND)
|| → logický součet (OR)
! → logická negace (NOT)
if((a == 1) && (b == 0)) {…}; // podmínka splněna, pokud a=1 A ZÁROVEŇ b=0
if((a == 1) || (b == 0)) {…}; // podmínka splněna, pokud a=1 NEBO b=0
if(a == !b) {…}; // podmínka splněna, pokud a je opak b (např. a = true a b=false
Rezistor
• Pasivní (nedodává energii) elekronická součástka, která klade
průchodu elektrického proudu odpor.
• Hodnota jeho odporu (rezistence) je závislá na teplotě.
• Při větším zatížení, než na které je rezistor určen, se zničí (přehřátím).
• Nezáleží na polaritě.
• Jednotka: Ω [Ohm]
• Rezistence se měří v jednotkách ohm, značeno Ω. Vztah napětí,
proudu a rezistence vyjadřuje Ohmův zákon:
kde I je proud v ampérech, U je napětí ve voltech a R je
odpor v ohmech. Pokud známe 2 veličiny, snadno dopočítáme třetí.
• Rezistor o odporu R = 1 Ω propustí při napětí U = 1 V proud I = 1 A.
• Rezistor o odporu 20 kΩ (tj. 20 000 Ω) propustí při napětí 100 V
proud o velikosti 100/20000, tj. 1/200 A, čili 5 mA.
• Pokud rezistorem o rezistenci 1000 Ω protéká proud 1 µA, tvoří se na
něm napětí 1 mV.
• Pokud víme, že rezistor při napětí 3 V propustil proud 10 mA, víme, že
má rezistenci 300 Ω.
Tlačítko
PROJECT: Arduino MakersLAB / Paralelní
Polis // Milan "Sodomák" Půlkrábek
Tlačítko
#DEFINE TLACITKO 2;
#DEFINE LED 13;
int stavTlacitka = 0;
void setup() {
pinMode(LED, OUTPUT);
pinMode(TLACITKO, INPUT);
}
void loop() {
stavTlacitka = digitalRead(TLACITKO);
if (stavTlacitka == HIGH) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
}
PROJECT: Arduino MakersLAB / Paralelní
Polis // Milan "Sodomák" Půlkrábek
Cykly
Cyklus for
#define LED 11
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
for (int i = 0; i < 256; i++) {
analogWrite(LED, i);
delay(10);
}
}
Cyklus while
#define LED 11
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
int i = 0;
while (i < 256)
{
analogWrite(LED, i);
delay(10);
i++;
}
}
Cyklus do - while
#define LED 11
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
int i = 0;
do {
analogWrite(LED, i);
delay(10);
i++;
}
while (i < 256);
}
Fotorezistor
• Fotorezistor (dříve označován jako fotoodpor) je pasivní elektronická
součástka , jejíž elektrický odpor se snižuje se zvyšující se intenzitou
dopadajícího světla, resp. elektrická vodivost se zvyšuje.
Teremin
Teremin
#define PINOUT 8
#define PININ A0
int vyska = 0;
int svetlo = 0;
void setup() {
pinMode(PINOUT, OUTPUT);
pinMode(PININ, INPUT);
}
void loop() {
svetlo = analogRead(PININ);
vyska = map(svetlo, 0, 1023, 100, 1000);
tone(PINOUT, vyska); // tone(pin, frequency(Hz), duration(ms))  noTone(pin)
}

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

PROJECT: Arduino 2

  • 2. Proměnné int pin = 13; int pauza = 1000; void setup() { pinMode(pin, OUTPUT); } void loop() { digitalWrite(pin, HIGH); delay(pauza); digitalWrite(pin, LOW); delay(pauza); } PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek
  • 3. Typy proměnných typ velikost rozsah signed unsigned char 8 b −128 až 127 0 až 255 int 16 b −32768 až 32767 0 až 65535 long 32 b −2147483648 až 2147483647 0 až 4294967295 boolean 8 b true nebo false PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek typ velikost rozsah float 32 b 3,4x1038 až 3,4x1038 double 64 b −1,7x10308 až 1,7x10308
  • 4. ASCII tabulka PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek
  • 5. Logické: • false – hodnota 0 • true – nejen 1, ale jakékoliv nenulové číslo Typ digitálního pinu: • OUTPUT – nastaví pin jako výstup (40mA) • INPUT – nastaví pin jako vstup • INPUT_PULLUP – jako INPUT, ale výchozí hodnota je HIGH (vnitřní rezistor připojen na +5V) Hodnoty napětí na pinu: • HIGH – 5V při výstupu, při vstupu pokud je větší než 3V • LOW – 0V při výstupu, při vstupu pokud je menší než 2V Vlastní: #define NÁZEV hodnota // bez středníku nebo const typ NÁZEV = hodnota; Konstanty
  • 6. Konstanty #define LED 13 void setup() { pinMode(LED, OUTPUT); } void loop() { digitalWrite(LED, HIGH); delay(1000); digitalWrite(LED, LOW); delay(1000); }
  • 7. Podmínka „if“ Syntaxe: if (podmínka) { příkazy... ; } else { příkazy... ; } } PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek
  • 8. Operátory podmínek Operátor Kompletní zápis Význam == x == y pokud se x rovná y != x != y pokud se x nerovná y < x < y pokud je x menší než y > x > y pokud je x větší než y <= x <= y pokud je x menší nebo rovno y >= x >= y pokud je x větší nebo rovno y PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek Kombinování podmínek: && → logický součin (AND) || → logický součet (OR) ! → logická negace (NOT) if((a == 1) && (b == 0)) {…}; // podmínka splněna, pokud a=1 A ZÁROVEŇ b=0 if((a == 1) || (b == 0)) {…}; // podmínka splněna, pokud a=1 NEBO b=0 if(a == !b) {…}; // podmínka splněna, pokud a je opak b (např. a = true a b=false
  • 9. Rezistor • Pasivní (nedodává energii) elekronická součástka, která klade průchodu elektrického proudu odpor. • Hodnota jeho odporu (rezistence) je závislá na teplotě. • Při větším zatížení, než na které je rezistor určen, se zničí (přehřátím). • Nezáleží na polaritě. • Jednotka: Ω [Ohm] • Rezistence se měří v jednotkách ohm, značeno Ω. Vztah napětí, proudu a rezistence vyjadřuje Ohmův zákon: kde I je proud v ampérech, U je napětí ve voltech a R je odpor v ohmech. Pokud známe 2 veličiny, snadno dopočítáme třetí. • Rezistor o odporu R = 1 Ω propustí při napětí U = 1 V proud I = 1 A. • Rezistor o odporu 20 kΩ (tj. 20 000 Ω) propustí při napětí 100 V proud o velikosti 100/20000, tj. 1/200 A, čili 5 mA. • Pokud rezistorem o rezistenci 1000 Ω protéká proud 1 µA, tvoří se na něm napětí 1 mV. • Pokud víme, že rezistor při napětí 3 V propustil proud 10 mA, víme, že má rezistenci 300 Ω.
  • 10. Tlačítko PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek
  • 11. Tlačítko #DEFINE TLACITKO 2; #DEFINE LED 13; int stavTlacitka = 0; void setup() { pinMode(LED, OUTPUT); pinMode(TLACITKO, INPUT); } void loop() { stavTlacitka = digitalRead(TLACITKO); if (stavTlacitka == HIGH) { digitalWrite(LED, HIGH); } else { digitalWrite(LED, LOW); } } PROJECT: Arduino MakersLAB / Paralelní Polis // Milan "Sodomák" Půlkrábek
  • 12. Cykly
  • 13. Cyklus for #define LED 11 void setup() { pinMode(LED, OUTPUT); } void loop() { for (int i = 0; i < 256; i++) { analogWrite(LED, i); delay(10); } }
  • 14. Cyklus while #define LED 11 void setup() { pinMode(LED, OUTPUT); } void loop() { int i = 0; while (i < 256) { analogWrite(LED, i); delay(10); i++; } }
  • 15. Cyklus do - while #define LED 11 void setup() { pinMode(LED, OUTPUT); } void loop() { int i = 0; do { analogWrite(LED, i); delay(10); i++; } while (i < 256); }
  • 16. Fotorezistor • Fotorezistor (dříve označován jako fotoodpor) je pasivní elektronická součástka , jejíž elektrický odpor se snižuje se zvyšující se intenzitou dopadajícího světla, resp. elektrická vodivost se zvyšuje.
  • 18. Teremin #define PINOUT 8 #define PININ A0 int vyska = 0; int svetlo = 0; void setup() { pinMode(PINOUT, OUTPUT); pinMode(PININ, INPUT); } void loop() { svetlo = analogRead(PININ); vyska = map(svetlo, 0, 1023, 100, 1000); tone(PINOUT, vyska); // tone(pin, frequency(Hz), duration(ms))  noTone(pin) }

Editor's Notes

  1. Při přetečení přeroluje na opačnou hodnotu int x; x = -32768; x = x - 1; // x now contains 32,767 - rolls over in neg. direction x = 32767; x = x + 1; // x now contains -32,768 - rolls over unsigned int cislo; signed char zaporne_cislo = -100; U předposledního příkladu chybí klíčové slovo signed nebo unsigned. Toto slovo je nepovinné a pokud jej neuvedeme, je proměnná automaticky se znaménkem.
  2. Break continue