Neuveriteľné pokusy o záchranu vesmíru pomocou Arduina: Rozdiel medzi revíziami
Skočit na navigaci
Skočit na vyhledávání
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 1: | Riadok 1: | ||
=== 1. úloha === | |||
'''Krátky popis:''' | |||
Program: | |||
<syntaxhighlight lang="C++"> | |||
void setup() | |||
{ | |||
Serial.begin(57600); | |||
} | |||
int i = 0; | |||
int j = 1; | |||
void loop() { | |||
if (i == 100) | |||
{ | |||
j = -1; | |||
} | |||
if (i == 0) | |||
{ | |||
j = 1; | |||
} | |||
Serial.print("Hello "); | |||
Serial.println(i); | |||
i = i + j; | |||
delay(70); | |||
} | |||
</syntaxhighlight> | |||
'''Čo program robí?''' | |||
'''Ako funguje?''' | |||
=== 2. úloha === | |||
'''Krátky popis:''' | |||
Program: | |||
<syntaxhighlight lang="C++"> | |||
#define LED 4 | |||
void setup() { | |||
pinMode(LED, OUTPUT); | |||
} | |||
void loop() { | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
delay(700); | |||
digitalWrite(LED, HIGH); | |||
delay(1000); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
digitalWrite(LED, HIGH); | |||
delay(1000); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
digitalWrite(LED, HIGH); | |||
delay(1000); | |||
digitalWrite(LED, LOW); | |||
delay(700); | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
delay(3000); | |||
} | |||
</syntaxhighlight> | |||
Kratšie riešenie: | |||
<syntaxhighlight lang="C++"> | |||
#define LED 4 | |||
void setup() | |||
{ | |||
pinMode(LED, OUTPUT); | |||
} | |||
void pismenoS() | |||
{ | |||
for (int i = 0; i < 3; i++) | |||
{ | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
} | |||
delay(400); | |||
} | |||
void pismenoO() | |||
{ | |||
for (int i = 0; i < 3; i++) | |||
{ | |||
digitalWrite(LED, HIGH); | |||
delay(1000); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
} | |||
delay(400); | |||
} | |||
void loop() | |||
{ | |||
pismenoS(); | |||
pismenoO(); | |||
pismenoS(); | |||
delay(600); | |||
} | |||
</syntaxhighlight> | |||
'''Čo program robí?''' | |||
'''Ako funguje?''' | |||
'''Ako sme program zjednodušili?''' | |||
=== 3. úloha === | |||
'''Krátky popis:''' | |||
Program - doplniť!: | |||
<syntaxhighlight lang="C++"> | |||
</syntaxhighlight> | |||
'''Čo program robí?''' | |||
'''Ako funguje?''' | |||
=== 4. úloha === | |||
'''Krátky popis:''' | |||
Program: | |||
<syntaxhighlight lang="C++"> | |||
#define LED 13 | |||
#define IRSENSOR 10 | |||
void setup() { | |||
Serial.begin(9600); | |||
pinMode(IRSENSOR, INPUT); | |||
pinMode(LED, OUTPUT); | |||
} | |||
void loop() { | |||
int sensor = digitalRead(IRSENSOR); | |||
if (sensor == 1) | |||
{ | |||
Serial.println("click"); | |||
while (sensor == 1) | |||
{ | |||
sensor = digitalRead(IRSENSOR); | |||
} | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
} | |||
} | |||
</syntaxhighlight> | |||
'''Čo program robí?''' | |||
'''Ako funguje?''' | |||
=== 4. úloha - druhá časť === | |||
'''Krátky popis:''' | |||
Program - nedokončený!: | |||
<syntaxhighlight lang="C++"> | |||
#define IRSENSOR 10 | |||
#define LED 13 | |||
void setup() { | |||
Serial.begin(9600); | |||
pinMode(IRSENSOR, INPUT); | |||
} | |||
/* premenne: | |||
kedy_sa_kliklo_prvy_raz | |||
ci_sa_uz_raz_kliklo = 0 | |||
precitaj senzor | |||
1. pripad: este sa nekliklo | |||
ak sa prave kliklo | |||
zapamataj cas do kedy_sa_kliklo_prvy_raz | |||
nastav ci_sa_uz_kliklo na 1 | |||
pockaj, kym clovek nepusti | |||
2. pripad: uz sa raz kliklo | |||
ak vyprsal cas na 2. kliknutie (stopky - kedy_sa_kliklo_prvy_raz > MAX_MEDZERA_DOUBLE_CLICK) | |||
vypis click | |||
nastav ci_sa_uz_raz_kliklo = 0 | |||
inak ak sa kliklo znova | |||
vypis double-click | |||
pockaj, kym clovek nepusti | |||
nastav ci_sa_uz_raz_kliklo = 0 | |||
*/ | |||
unsigned long kedy_sa_kliklo_prvy_raz; | |||
int ci_sa_uz_raz_kliklo = 0; | |||
void loop() { | |||
int sensor = digitalRead(IRSENSOR); | |||
if (ci_sa_uz_raz_kliklo == 0) | |||
{ | |||
if (sensor == 1) | |||
{ | |||
kedy_sa_kliklo_prvy_raz = millis(); | |||
ci_sa_uz_raz_kliklo = 1; | |||
while (sensor == 1) | |||
sensor = digitalRead(IRSENSOR); | |||
} | |||
} | |||
else | |||
{ | |||
} | |||
if (sensor == 1) | |||
{ | |||
Serial.println("click"); | |||
while (sensor == 1) | |||
sensor = digitalRead(IRSENSOR); | |||
digitalWrite(LED, HIGH); | |||
delay(500); | |||
digitalWrite(LED, LOW); | |||
} | |||
delay(300); | |||
} | |||
</syntaxhighlight> | |||
'''Čo program robí?''' | |||
'''Ako funguje?''' | |||
=== 5. úloha === | |||
'''Krátky popis:''' | |||
Program - doplniť: | |||
<syntaxhighlight lang="C++"> | |||
</syntaxhighlight> | |||
'''Čo program robí?''' | |||
'''Ako funguje?''' | |||
=== 6. úloha === | |||
'''Krátky popis:''' V nasom programe sme pouzili JOYstick ktorym riadime servo motor LED a bzuciak | |||
Program: | Program: | ||
Riadok 10: | Riadok 306: | ||
#include <Servo.h> | #include <Servo.h> | ||
Servo s; | Servo s; | ||
Riadok 25: | Riadok 320: | ||
// zasvietime LED postupne slabne svetlo | // zasvietime LED postupne slabne svetlo | ||
for (int i = 255; i >= 0; i--) | |||
{ | |||
analogWrite(6, i); | |||
delay(5); | |||
} | |||
// pripojime servo na pin D7 | // pripojime servo na pin D7 | ||
Riadok 50: | Riadok 339: | ||
delay(1000); | delay(1000); | ||
} | } | ||
int pipa=0; // ked je pipa == 1 riadime bzuciak, servo, aj LED | int pipa=0; // ked je pipa == 1 riadime bzuciak, servo, aj LED | ||
void loop() | void loop() | ||
Riadok 87: | Riadok 374: | ||
delay(300); | delay(300); | ||
} | } | ||
</syntaxhighlight> | |||
'''Čo program robí?''' | |||
'''Ako funguje?''' | |||
<youtube>ON-MnqfiEUY</youtube> | <youtube>ON-MnqfiEUY</youtube> | ||
__notoc__ |
Verzia z 05:20, 3. december 2023
1. úloha
Krátky popis:
Program:
void setup()
{
Serial.begin(57600);
}
int i = 0;
int j = 1;
void loop() {
if (i == 100)
{
j = -1;
}
if (i == 0)
{
j = 1;
}
Serial.print("Hello ");
Serial.println(i);
i = i + j;
delay(70);
}
Čo program robí?
Ako funguje?
2. úloha
Krátky popis:
Program:
#define LED 4
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(300);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(300);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(700);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(300);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(300);
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(700);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(300);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(300);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(3000);
}
Kratšie riešenie:
#define LED 4
void setup()
{
pinMode(LED, OUTPUT);
}
void pismenoS()
{
for (int i = 0; i < 3; i++)
{
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(300);
}
delay(400);
}
void pismenoO()
{
for (int i = 0; i < 3; i++)
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(300);
}
delay(400);
}
void loop()
{
pismenoS();
pismenoO();
pismenoS();
delay(600);
}
Čo program robí?
Ako funguje?
Ako sme program zjednodušili?
3. úloha
Krátky popis:
Program - doplniť!:
Čo program robí?
Ako funguje?
4. úloha
Krátky popis:
Program:
#define LED 13
#define IRSENSOR 10
void setup() {
Serial.begin(9600);
pinMode(IRSENSOR, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
int sensor = digitalRead(IRSENSOR);
if (sensor == 1)
{
Serial.println("click");
while (sensor == 1)
{
sensor = digitalRead(IRSENSOR);
}
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
}
}
Čo program robí?
Ako funguje?
4. úloha - druhá časť
Krátky popis:
Program - nedokončený!:
#define IRSENSOR 10
#define LED 13
void setup() {
Serial.begin(9600);
pinMode(IRSENSOR, INPUT);
}
/* premenne:
kedy_sa_kliklo_prvy_raz
ci_sa_uz_raz_kliklo = 0
precitaj senzor
1. pripad: este sa nekliklo
ak sa prave kliklo
zapamataj cas do kedy_sa_kliklo_prvy_raz
nastav ci_sa_uz_kliklo na 1
pockaj, kym clovek nepusti
2. pripad: uz sa raz kliklo
ak vyprsal cas na 2. kliknutie (stopky - kedy_sa_kliklo_prvy_raz > MAX_MEDZERA_DOUBLE_CLICK)
vypis click
nastav ci_sa_uz_raz_kliklo = 0
inak ak sa kliklo znova
vypis double-click
pockaj, kym clovek nepusti
nastav ci_sa_uz_raz_kliklo = 0
*/
unsigned long kedy_sa_kliklo_prvy_raz;
int ci_sa_uz_raz_kliklo = 0;
void loop() {
int sensor = digitalRead(IRSENSOR);
if (ci_sa_uz_raz_kliklo == 0)
{
if (sensor == 1)
{
kedy_sa_kliklo_prvy_raz = millis();
ci_sa_uz_raz_kliklo = 1;
while (sensor == 1)
sensor = digitalRead(IRSENSOR);
}
}
else
{
}
if (sensor == 1)
{
Serial.println("click");
while (sensor == 1)
sensor = digitalRead(IRSENSOR);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
}
delay(300);
}
Čo program robí?
Ako funguje?
5. úloha
Krátky popis:
Program - doplniť:
Čo program robí?
Ako funguje?
6. úloha
Krátky popis: V nasom programe sme pouzili JOYstick ktorym riadime servo motor LED a bzuciak
Program:
#define JOY_X 0 // this represents pin A0
#define JOY_Y 1 // this represents pin A1
#define JOY_SW 5 // this represents pin D5
#define JOY_D4 // this represents pin D4
#include <Servo.h>
Servo s;
void setup() {
pinMode(JOY_SW, INPUT);
digitalWrite(JOY_SW, HIGH); // this turns on internal pull-up, because the switch
// has two modes: disconnected or grounded, so we have
// to make sure we read logical 1 when it is disconnected
Serial.begin(9600);
// na zaciatku zapipame
tone(3, 880, 500);
// zasvietime LED postupne slabne svetlo
for (int i = 255; i >= 0; i--)
{
analogWrite(6, i);
delay(5);
}
// pripojime servo na pin D7
s.attach(7);
// pohneme servo do krajnych poloh
s.write(1);
delay(1000);
s.write(178);
delay(1000);
// a potom do stredu
s.write(90);
delay(1000);
}
int pipa=0; // ked je pipa == 1 riadime bzuciak, servo, aj LED
void loop()
{
int x = analogRead(JOY_X);
int y = analogRead(JOY_Y);
int sw = digitalRead(JOY_SW);
if (sw==0) // ak stlacil joystick
{
// prepneme riadenie on/off
pipa = 1 - pipa;
while (sw==0) // pockame kym pusti kliknutie
{
sw = digitalRead(JOY_SW);
}
delay(50);
}
if (pipa == 1) // ak riadime
{
analogWrite(6, x / 4); // LED
tone(3, x*2, 50); // bzuciak
s.write(1+x*32/183); // servo
}
// vypiseme polohy pacok serva
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.print(" ");
Serial.println(sw);
delay(300);
}
Čo program robí?
Ako funguje?