Neuveriteľné pokusy o záchranu vesmíru pomocou Arduina: Rozdiel medzi revíziami
dBez shrnutí editace |
dBez shrnutí editace |
||
(3 medziľahlé úpravy od 2 ďalších používateľov nie sú zobrazené) | |||
Riadok 295: | Riadok 295: | ||
<syntaxhighlight lang="C++"> | <syntaxhighlight lang="C++"> | ||
#define BUZZER 7 | |||
#define LED 13 | |||
void setup() { | |||
pinMode(BUZZER, OUTPUT); | |||
pinMode(LED, OUTPUT); | |||
Serial.begin(9600); | |||
} | |||
void cpip(int d) | |||
{ | |||
int dlzka = d * 250000L / (956 * 2); | |||
digitalWrite(LED, HIGH); | |||
for (int i = 0; i < dlzka; i++) | |||
{ | |||
digitalWrite(BUZZER, HIGH); | |||
delayMicroseconds(956); | |||
digitalWrite(BUZZER, LOW); | |||
delayMicroseconds(956); | |||
} | |||
digitalWrite(LED, LOW); | |||
} | |||
void dpip(int d) | |||
{ | |||
int dlzka = d * 250000L / (851 * 2); | |||
digitalWrite(LED, HIGH); | |||
for (int i = 0; i < dlzka; i++) | |||
{ | |||
digitalWrite(BUZZER, HIGH); | |||
delayMicroseconds(851); | |||
digitalWrite(BUZZER, LOW); | |||
delayMicroseconds(851); | |||
} | |||
digitalWrite(LED, LOW); | |||
} | |||
void epip(int d) | |||
{ | |||
int dlzka = d * 250000L / (758 * 2); | |||
digitalWrite(LED, HIGH); | |||
for (int i = 0; i < dlzka; i++) | |||
{ | |||
digitalWrite(BUZZER, HIGH); | |||
delayMicroseconds(758); | |||
digitalWrite(BUZZER, LOW); | |||
delayMicroseconds(758); | |||
} | |||
digitalWrite(LED, LOW); | |||
} | |||
void fpip(int d) | |||
{ | |||
int dlzka = d * 250000L / (716 * 2); | |||
digitalWrite(LED, HIGH); | |||
for (int i = 0; i < dlzka; i++) | |||
{ | |||
digitalWrite(BUZZER, HIGH); | |||
delayMicroseconds(716); | |||
digitalWrite(BUZZER, LOW); | |||
delayMicroseconds(716); | |||
} | |||
digitalWrite(LED, LOW); | |||
} | |||
int zahraj(char c, int d) | |||
{ | |||
if (c == 'z') cpip(d); | |||
else if (c == 'x') dpip(d); | |||
else if (c == 'c') epip(d); | |||
else if (c == 'v') fpip(d); | |||
else return 0; | |||
return 1; | |||
} | |||
// kohutik: zxcvvvvcxccccxzxxxxcxzzz | |||
char melodia[] = "zxcvvvvcxccccxzxxxxcxzzz"; | |||
char rytmus[] = "224422224422224422224422"; | |||
void mel() | |||
{ | |||
for (int i = 0; i < strlen(melodia); i++) | |||
{ | |||
char c = melodia[i]; | |||
char r = rytmus[i]; | |||
zahraj(c, r - '0'); | |||
delay(50); | |||
} | |||
} | |||
void loop() | |||
{ | |||
if (Serial.available()) | |||
{ | |||
char c = Serial.read(); | |||
if (!zahraj(c, 2)) | |||
if (c == ' ') mel(); | |||
} | |||
digitalWrite(LED, HIGH); | |||
delay(100); | |||
digitalWrite(LED, LOW); | |||
delay(300); | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<youtube>plSbTSCHGFU</youtube> | |||
'''Čo program robí?''' | '''Čo program robí?''' | ||
Riadok 392: | Riadok 497: | ||
<youtube>ON-MnqfiEUY</youtube> | <youtube>ON-MnqfiEUY</youtube> | ||
----- | |||
Alarm: | |||
<syntaxhighlight lang="C++"> | |||
#define MICROPHONE 1 | |||
int position; | |||
void setup() { | |||
Serial.begin(9600); | |||
} | |||
int measure_amplitude() | |||
{ | |||
int min = 1023; | |||
int max = 0; | |||
for (int i = 0; i < 5000; i++) | |||
{ | |||
int val = analogRead(MICROPHONE); | |||
if (val > max) max = val; | |||
if (val < min) min = val; | |||
} | |||
return (max - min) / 2; | |||
} | |||
void loop() | |||
{ | |||
int loudness = measure_amplitude(); | |||
Serial.println(loudness); | |||
delay(100); | |||
if (loudness > 200) | |||
{ | |||
for (int i = 0; i < 4; i++) | |||
{ | |||
tone(16, 880, 500); | |||
delay(505); | |||
tone(16, 1760, 800); | |||
delay(500); | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
<youtube>_YmTJoqIAYw</youtube> | |||
----- | ----- | ||
Záznam rytmu: | Záznam rytmu: | ||
<syntaxhighlight lang="C++"> | |||
#define MICROPHONE 1 | |||
int position; | |||
void setup() { | |||
Serial.begin(9600); | |||
} | |||
int measure_amplitude() | |||
{ | |||
int min = 1023; | |||
int max = 0; | |||
for (int i = 0; i < 100; i++) | |||
{ | |||
int val = analogRead(MICROPHONE); | |||
if (val > max) max = val; | |||
if (val < min) min = val; | |||
} | |||
return (max - min) / 2; | |||
} | |||
unsigned long kedy_tleskol = 0; | |||
int pozicia = 0; | |||
int rytmus[100]; | |||
void loop() | |||
{ | |||
int loudness = measure_amplitude(); | |||
//Serial.println(loudness); | |||
//delay(100); | |||
if (loudness > 200) | |||
{ | |||
if (kedy_tleskol != 0) | |||
{ | |||
Serial.println(millis() - kedy_tleskol); | |||
rytmus[pozicia] = millis() - kedy_tleskol; | |||
pozicia++; | |||
} | |||
kedy_tleskol = millis(); | |||
delay(250); | |||
} | |||
else if (kedy_tleskol != 0) | |||
{ | |||
if (millis() - kedy_tleskol > 5000) | |||
{ | |||
Serial.println("koniec rytmu"); | |||
kedy_tleskol = 0; | |||
for (int i = 0; i < pozicia; i++) | |||
{ | |||
tone(16, 880, 100); | |||
delay(rytmus[i]); | |||
} | |||
tone(16, 880, 100); | |||
pozicia = 0; | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
<youtube>NhTpvo0j5lY</youtube> | <youtube>NhTpvo0j5lY</youtube> | ||
----- | |||
BONUS: riadenie farby RGB LEDky: | |||
<syntaxhighlight lang="C++"> | |||
#define CERVENA 6 | |||
#define ZELENA 3 | |||
#define MODRA 5 | |||
// v premennych c, z, m bude intenzita cervenej, zelenej a modrej zlozky | |||
int c, z, m; | |||
void setup() { | |||
// vsetky tri ledky nastavime ako vystupne | |||
// pomocou funkcie pinMode(led, OUTPUT); | |||
pinMode(CERVENA, OUTPUT); | |||
pinMode(MODRA, OUTPUT); | |||
pinMode(ZELENA, OUTPUT); | |||
// nastavime bielu | |||
analogWrite(CERVENA, 50); | |||
analogWrite(ZELENA, 50); | |||
analogWrite(MODRA, 50); | |||
// inicializujeme seriovy port na 9600 bps | |||
Serial.begin(9600); | |||
delay(300); | |||
Serial.println("rgb"); | |||
c = 255; | |||
z = 255; | |||
m = 255; | |||
} | |||
void vypis() | |||
{ | |||
Serial.print("c="); | |||
Serial.print(c); | |||
Serial.print(",z="); | |||
Serial.print(z); | |||
Serial.print(",m="); | |||
Serial.println(m); | |||
} | |||
void loop() { | |||
// zistime, ci nieco prislo zo serioveho portu | |||
if (Serial.available()) | |||
{ | |||
// precitame znak zo serioveho portu | |||
char znak = Serial.read(); | |||
Serial.print("z="); | |||
Serial.println(znak); | |||
// podla toho aky znak prisiel budeme menit | |||
// jas jednotlivych zloziek RGB | |||
switch (znak) { | |||
case 'Q': // zosilnit cervenu | |||
if (c < 255) | |||
{ | |||
c++; | |||
analogWrite(CERVENA, c); | |||
vypis(); | |||
} | |||
break; | |||
case 'q': // zoslabit cervenu | |||
if (c > 0) | |||
{ | |||
c--; | |||
analogWrite(CERVENA, c); | |||
vypis(); | |||
} | |||
break; | |||
case 'W': // zosilnit modru | |||
if (m < 255) | |||
{ | |||
m++; | |||
analogWrite(MODRA, m); | |||
vypis(); | |||
} | |||
break; | |||
case 'w': // zoslabit modru | |||
if (m > 0) | |||
{ | |||
m--; | |||
analogWrite(MODRA, m); | |||
vypis(); | |||
} | |||
break; | |||
case 'E': // zosilnit ZELENA | |||
if (z < 255) | |||
{ | |||
z++; | |||
analogWrite(ZELENA, z); | |||
vypis(); | |||
} | |||
break; | |||
case 'e': // zoslabit ZELENA | |||
if (z > 0) | |||
{ | |||
z--; | |||
analogWrite(ZELENA, z); | |||
vypis(); | |||
} | |||
break; | |||
case 'z': // nastav ZELENU | |||
z = 50; | |||
c = 0; | |||
m = 0; | |||
analogWrite(ZELENA, z); | |||
analogWrite(CERVENA, c); | |||
analogWrite(MODRA, m); | |||
vypis(); | |||
break; | |||
case 'c': // nastav CERVENU | |||
z = 0; | |||
c = 50; | |||
m = 0; | |||
analogWrite(ZELENA, z); | |||
analogWrite(CERVENA, c); | |||
analogWrite(MODRA, m); | |||
vypis(); | |||
break; | |||
case 'm': // nastav MODRU | |||
z = 0; | |||
c = 0; | |||
m = 50; | |||
analogWrite(ZELENA, z); | |||
analogWrite(CERVENA, c); | |||
analogWrite(MODRA, m); | |||
vypis(); | |||
break; | |||
case 'b': // nastav BIELU | |||
z = 50; | |||
c = 50; | |||
m = 50; | |||
analogWrite(ZELENA, z); | |||
analogWrite(CERVENA, c); | |||
analogWrite(MODRA, m); | |||
vypis(); | |||
break; | |||
case ' ': // nastav CIERNU | |||
z = 0; | |||
c = 0; | |||
m = 0; | |||
analogWrite(ZELENA, z); | |||
analogWrite(CERVENA, c); | |||
analogWrite(MODRA, m); | |||
vypis(); | |||
break; | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
<youtube>eV_0__VrVqk</youtube> | |||
__notoc__ | __notoc__ |
Aktuálna revízia z 17:36, 19. január 2024
1. úloha
Krátky popis:
Príklad programu, ktorý vypisuje informácie na sériovú linku, takže si jeho výpisy môžeme pozrieť v Serial Monitore.
a načo vlastne je tento program?
pomocou Seterovej vysielačky program vysiela čísla do zariadenia v Serene(hviezde) čim riadime výbuchy na Serene a tým udržujeme pravidelne počasia na neďalekej planéte a tým pomáhame prežiť ešte nevyvinutej civilizácii (sú zrýchlení)
Program:
void setup()
{
Serial.begin(57600); // nastavit komunikacnu rychlost seriovej linky (kolko bitov za sekundu sa prenesie)
}
int i = 0;
int j = 1;
void loop() {
if (i == 100)
{
j = -1;
}
if (i == 0)
{
j = 1;
}
Serial.print("Hello "); // tímto vipiseme hello
Serial.println(i); // tímto vipisujeme hodnotu premenej i
i = i + j;
delay(70);
}
Čo program robí? program po jednom mení čísla smerom nahor a keď čísla dosiahnu 100, mení čísla smerom nadol a keď dosiahne 0, začne od začiatku. Čísla vypisuje do sériovej linky.
Ako funguje? V každom opakovaní cyklu mení premennú i o hodnotu j, ktorá je buď 1 alebo -1 - podľa toho, či majú práve čísla rásť alebo klesať. Keď počítadlo - premenná i - dosiahne okrajovú hodnotu 100 alebo 0, tak sa zmení hodnota j.
2. úloha
Krátky popis: program ukazuje, ako sa dajú riadiť výstupy - napríklad svietiť diodou. Na výstup pošleme logickú 1 - vtedy tam bude 5V, alebo logickú 0 - vtedy tam bude 0V.
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í? (čo pán učitel chce počuť) vysiela signál sos
(realita) zahrieva reaktor ktorý posiela fotky z planéty Erisan (poloha sústava Arius) a vďaka tomu vieme čo sa deje kebyže toto dôležité zariadenie vypneme tak reaktor zamrzne (poloha: Mars)
Ako funguje? (čo pán učitel chce počuť) bliká LEDka raz blikne na dlho a raz na krátko a to sa vždy opakuje 3x (realita) funguje na princípe rediačného systému ktorý pochádza z planéty Avaspaj
Ako sme program zjednodušili? (čo pán učitel chce počuť) opakujúce sa časti sme nahradili cyklom a vytvorili sme nové funkcie pre odvysielanie písmena S aj O (realita) napojili sme ho na princípe rediačného
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ť:
#define BUZZER 7
#define LED 13
void setup() {
pinMode(BUZZER, OUTPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void cpip(int d)
{
int dlzka = d * 250000L / (956 * 2);
digitalWrite(LED, HIGH);
for (int i = 0; i < dlzka; i++)
{
digitalWrite(BUZZER, HIGH);
delayMicroseconds(956);
digitalWrite(BUZZER, LOW);
delayMicroseconds(956);
}
digitalWrite(LED, LOW);
}
void dpip(int d)
{
int dlzka = d * 250000L / (851 * 2);
digitalWrite(LED, HIGH);
for (int i = 0; i < dlzka; i++)
{
digitalWrite(BUZZER, HIGH);
delayMicroseconds(851);
digitalWrite(BUZZER, LOW);
delayMicroseconds(851);
}
digitalWrite(LED, LOW);
}
void epip(int d)
{
int dlzka = d * 250000L / (758 * 2);
digitalWrite(LED, HIGH);
for (int i = 0; i < dlzka; i++)
{
digitalWrite(BUZZER, HIGH);
delayMicroseconds(758);
digitalWrite(BUZZER, LOW);
delayMicroseconds(758);
}
digitalWrite(LED, LOW);
}
void fpip(int d)
{
int dlzka = d * 250000L / (716 * 2);
digitalWrite(LED, HIGH);
for (int i = 0; i < dlzka; i++)
{
digitalWrite(BUZZER, HIGH);
delayMicroseconds(716);
digitalWrite(BUZZER, LOW);
delayMicroseconds(716);
}
digitalWrite(LED, LOW);
}
int zahraj(char c, int d)
{
if (c == 'z') cpip(d);
else if (c == 'x') dpip(d);
else if (c == 'c') epip(d);
else if (c == 'v') fpip(d);
else return 0;
return 1;
}
// kohutik: zxcvvvvcxccccxzxxxxcxzzz
char melodia[] = "zxcvvvvcxccccxzxxxxcxzzz";
char rytmus[] = "224422224422224422224422";
void mel()
{
for (int i = 0; i < strlen(melodia); i++)
{
char c = melodia[i];
char r = rytmus[i];
zahraj(c, r - '0');
delay(50);
}
}
void loop()
{
if (Serial.available())
{
char c = Serial.read();
if (!zahraj(c, 2))
if (c == ' ') mel();
}
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
delay(300);
}
Č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?
Alarm:
#define MICROPHONE 1
int position;
void setup() {
Serial.begin(9600);
}
int measure_amplitude()
{
int min = 1023;
int max = 0;
for (int i = 0; i < 5000; i++)
{
int val = analogRead(MICROPHONE);
if (val > max) max = val;
if (val < min) min = val;
}
return (max - min) / 2;
}
void loop()
{
int loudness = measure_amplitude();
Serial.println(loudness);
delay(100);
if (loudness > 200)
{
for (int i = 0; i < 4; i++)
{
tone(16, 880, 500);
delay(505);
tone(16, 1760, 800);
delay(500);
}
}
}
Záznam rytmu:
#define MICROPHONE 1
int position;
void setup() {
Serial.begin(9600);
}
int measure_amplitude()
{
int min = 1023;
int max = 0;
for (int i = 0; i < 100; i++)
{
int val = analogRead(MICROPHONE);
if (val > max) max = val;
if (val < min) min = val;
}
return (max - min) / 2;
}
unsigned long kedy_tleskol = 0;
int pozicia = 0;
int rytmus[100];
void loop()
{
int loudness = measure_amplitude();
//Serial.println(loudness);
//delay(100);
if (loudness > 200)
{
if (kedy_tleskol != 0)
{
Serial.println(millis() - kedy_tleskol);
rytmus[pozicia] = millis() - kedy_tleskol;
pozicia++;
}
kedy_tleskol = millis();
delay(250);
}
else if (kedy_tleskol != 0)
{
if (millis() - kedy_tleskol > 5000)
{
Serial.println("koniec rytmu");
kedy_tleskol = 0;
for (int i = 0; i < pozicia; i++)
{
tone(16, 880, 100);
delay(rytmus[i]);
}
tone(16, 880, 100);
pozicia = 0;
}
}
}
BONUS: riadenie farby RGB LEDky:
#define CERVENA 6
#define ZELENA 3
#define MODRA 5
// v premennych c, z, m bude intenzita cervenej, zelenej a modrej zlozky
int c, z, m;
void setup() {
// vsetky tri ledky nastavime ako vystupne
// pomocou funkcie pinMode(led, OUTPUT);
pinMode(CERVENA, OUTPUT);
pinMode(MODRA, OUTPUT);
pinMode(ZELENA, OUTPUT);
// nastavime bielu
analogWrite(CERVENA, 50);
analogWrite(ZELENA, 50);
analogWrite(MODRA, 50);
// inicializujeme seriovy port na 9600 bps
Serial.begin(9600);
delay(300);
Serial.println("rgb");
c = 255;
z = 255;
m = 255;
}
void vypis()
{
Serial.print("c=");
Serial.print(c);
Serial.print(",z=");
Serial.print(z);
Serial.print(",m=");
Serial.println(m);
}
void loop() {
// zistime, ci nieco prislo zo serioveho portu
if (Serial.available())
{
// precitame znak zo serioveho portu
char znak = Serial.read();
Serial.print("z=");
Serial.println(znak);
// podla toho aky znak prisiel budeme menit
// jas jednotlivych zloziek RGB
switch (znak) {
case 'Q': // zosilnit cervenu
if (c < 255)
{
c++;
analogWrite(CERVENA, c);
vypis();
}
break;
case 'q': // zoslabit cervenu
if (c > 0)
{
c--;
analogWrite(CERVENA, c);
vypis();
}
break;
case 'W': // zosilnit modru
if (m < 255)
{
m++;
analogWrite(MODRA, m);
vypis();
}
break;
case 'w': // zoslabit modru
if (m > 0)
{
m--;
analogWrite(MODRA, m);
vypis();
}
break;
case 'E': // zosilnit ZELENA
if (z < 255)
{
z++;
analogWrite(ZELENA, z);
vypis();
}
break;
case 'e': // zoslabit ZELENA
if (z > 0)
{
z--;
analogWrite(ZELENA, z);
vypis();
}
break;
case 'z': // nastav ZELENU
z = 50;
c = 0;
m = 0;
analogWrite(ZELENA, z);
analogWrite(CERVENA, c);
analogWrite(MODRA, m);
vypis();
break;
case 'c': // nastav CERVENU
z = 0;
c = 50;
m = 0;
analogWrite(ZELENA, z);
analogWrite(CERVENA, c);
analogWrite(MODRA, m);
vypis();
break;
case 'm': // nastav MODRU
z = 0;
c = 0;
m = 50;
analogWrite(ZELENA, z);
analogWrite(CERVENA, c);
analogWrite(MODRA, m);
vypis();
break;
case 'b': // nastav BIELU
z = 50;
c = 50;
m = 50;
analogWrite(ZELENA, z);
analogWrite(CERVENA, c);
analogWrite(MODRA, m);
vypis();
break;
case ' ': // nastav CIERNU
z = 0;
c = 0;
m = 0;
analogWrite(ZELENA, z);
analogWrite(CERVENA, c);
analogWrite(MODRA, m);
vypis();
break;
}
}
}