OVLÁDÁNÍ LED
Připojení LED k Arduinu a ovládání
Řada LED Vytvořit efekt prodleva 0,5s
voidSetup() { pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); } voidLoop() { digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW); digitalWrite(12, LOW); digitalWrite(13,LOW); delay(500);
digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, LOW); digitalWrite(11, LOW); digitalWrite(12, LOW); digitalWrite(13,LOW); delay(500); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, HIGH); digitalWrite(11, LOW); digitalWrite(12, LOW); digitalWrite(13,LOW); delay(500);
digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH); digitalWrite(12, LOW); digitalWrite(13,LOW); delay(500); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW); digitalWrite(12, HIGH); digitalWrite(13,LOW); delay(500);
digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH); digitalWrite(12, LOW); digitalWrite(13,HIGH); delay(500); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW); digitalWrite(12, HIGH); digitalWrite(13,LOW); delay(500);
digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH); digitalWrite(12, LOW); digitalWrite(13,LOW); delay(500); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, HIGH); digitalWrite(11, LOW); digitalWrite(12, LOW); digitalWrite(13,LOW); delay(500);
digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, LOW); digitalWrite(11, LOW); digitalWrite(12, LOW); digitalWrite(13,LOW); delay(500); } Ač by tento program pracoval – tak takto NE!!!!!!!!!!!!!! Představme si jednotlivě sled efektu jako tabulku 0 a 1 a převeďme jí do pole a nalezněme vztah pro polohu prvku v tabulce a v poli.
Sloupec řádek
r - řádka v tabulce s - sloupec v tabulce i - index pole i = r. 6 + s Př.: r = 2 s = 4 i = = 16
int Index; int LedPole[] = {1,0,0,0,0,0,// naplnění pole efektem 0,1,0,0,0,0, 0,0,1,0,0,0, 0,0,0,1,0,0, 0,0,0,0,1,0, 0,0,0,0,0,1, 0,0,0,0,1,0, 0,0,0,1,0,0, 0,0,1,0,0,0, 0,1,0,0,0,0}; void setup() { for ( int Pin =8 ; Pin < 14; Pin++)// nastavení pinů s LED jako výstupní {pinMode(Pin, OUTPUT); } }
void loop { for ( int Radek =0 ; Radek < 10; Radek++)// postupný průchod tabulkou {for ( int Sloupec =0 ; Sloupec < 6; Sloupec++)//po řádcích { Index = Radek * 6 + Sloupec ;//převod na pozici v poli if (LedPole [Index]==1) {digitalWrite(Sloupec + 8, HIGH); }//zobrazení else {digitalWrite(Sloupec + 8, LOW; } } delay(500); }