Po wielu latach bezczynności udało się odpalić projekt Arduino ponownie... I trzeba się zacząć uczyć ponownie... To co mnie miło zaskoczyło to że jak tym razem zainstalowałem oprogramowanie Arduino to od razu wszystko zadziałało.
Któregoś dnia wykasowałem z googla+ przypadkowo wszystkie grafiki z bloga, przez co nie ma ich przy projektach... powoli je uzupełniam robiąc projekty na nowo. W końcu należy sobie wszystko przypomnieć.
W ramach przypomnienia zrobiłem sobie mały projekt z 10 LEDami i sobie le powłączałem i powyłączałem w różnych kombinacjach, poniżej kod... Zastanawiałem się czy nie można by go uprościć, np zrobić void on i off a potrm tylko on(1) zmienna z żarówką, którą chciałbym włączyć czy wyłączyć... może ktoś ma pomysł jak skrócić kod...
const int ledCount = 10;
int ledPins[] = { 4, 5, 6, 7, 8, 9,10,11,12,13 };
void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop()
{
on1(); on2(); on3(); on4(); on5(); on6(); on7(); on8(); on9(); on10();
delay(500);
off1(); off2(); off3(); off4(); off5(); off6(); off7(); off8(); off9(); off10();
delay(500);
on1(); on2(); on3(); on4(); on5(); on6(); on7(); on8(); on9(); on10();
delay(500);
off1(); off2(); off3(); off4(); off5(); off6(); off7(); off8(); off9(); off10();
delay(1000);
on1(); delay(100); on2(); delay(100); on3(); delay(100); on4(); delay(100); on5(); delay(100); on6(); delay(100); on7(); delay(100); on8(); delay(100); on9(); delay(100); on10();delay(100);
off1(); delay(100); off2(); delay(100); off3(); delay(100); off4(); delay(100); off5(); delay(100); off6(); delay(100); off7(); delay(100); off8(); delay(100); off9(); delay(100); off10();
delay(100);
on1(); delay(100); on2(); delay(100); on3(); delay(100); on4(); delay(100); on5(); delay(100); on6(); delay(100); on7(); delay(100); on8(); delay(100); on9(); delay(100); on10();delay(100);
off1(); delay(100); off2(); delay(100); off3(); delay(100); off4(); delay(100); off5(); delay(100); off6(); delay(100); off7(); delay(100); off8(); delay(100); off9(); delay(100); off10();
delay(1000);
on1(); delay(100); off1(); on2(); delay(100); off2(); on3(); delay(100); off3(); on4(); delay(100); off4(); on5(); delay(100); off5(); on6(); delay(100); off6(); on7(); delay(100); off7(); on8(); delay(100); off8(); on9(); delay(100); off9(); on10(); delay(100); off10();
delay(100);
on10(); delay(100); off10(); on9(); delay(100); off9(); on8(); delay(100); off8(); on7(); delay(100); off7(); on6(); delay(100); off6(); on5(); delay(100); off5(); on4(); delay(100); off4(); on3(); delay(100); off3(); on2(); delay(100); off2(); on1(); delay(100); off1();
delay(100);
on1(); delay(100); off1(); on2(); delay(100); off2(); on3(); delay(100); off3(); on4(); delay(100); off4(); on5(); delay(100); off5(); on6(); delay(100); off6(); on7(); delay(100); off7(); on8(); delay(100); off8(); on9(); delay(100); off9(); on10(); delay(100); off10();
delay(100);
on10(); delay(100); off10(); on9(); delay(100); off9(); on8(); delay(100); off8(); on7(); delay(100); off7(); on6(); delay(100); off6(); on5(); delay(100); off5(); on4(); delay(100); off4(); on3(); delay(100); off3(); on2(); delay(100); off2(); on1(); delay(100); off1();
delay(1000);
on1(); on10(); delay(100); on2(); on9(); off1(); off10(); delay(100); on3(); on8(); off2(); off9(); delay(100); on4(); on7(); off3(); off8(); delay(100); on5(); on6(); off4(); off7(); delay(100); off5(); off6(); delay(100);on5(); on6(); delay(100); on4(); on7(); off5(); off6(); delay(100); on3(); on8(); off4(); off7(); delay(100); on2(); on9(); off3(); off8(); delay(100); on1(); on10(); off2(); off9(); delay(100); off1(); off10();
delay(100);
on1(); on10(); delay(100); on2(); on9(); off1(); off10(); delay(100); on3(); on8(); off2(); off9(); delay(100); on4(); on7(); off3(); off8(); delay(100); on5(); on6(); off4(); off7(); delay(100); off5(); off6(); delay(100);on5(); on6(); delay(100); on4(); on7(); off5(); off6(); delay(100); on3(); on8(); off4(); off7(); delay(100); on2(); on9(); off3(); off8(); delay(100); on1(); on10(); off2(); off9(); delay(100); off1(); off10();
delay(1000);
}
void on1(){ digitalWrite( 4, HIGH); }
void on2(){ digitalWrite( 5, HIGH); }
void on3(){ digitalWrite( 6, HIGH); }
void on4(){ digitalWrite( 7, HIGH); }
void on5(){ digitalWrite( 8, HIGH); }
void on6(){ digitalWrite( 9, HIGH); }
void on7(){ digitalWrite(10, HIGH); }
void on8(){ digitalWrite(11, HIGH); }
void on9(){ digitalWrite(12, HIGH); }
void on10(){ digitalWrite(13, HIGH); }
void off1(){ digitalWrite( 4, LOW); }
void off2(){ digitalWrite( 5, LOW); }
void off3(){ digitalWrite( 6, LOW); }
void off4(){ digitalWrite( 7, LOW); }
void off5(){ digitalWrite( 8, LOW); }
void off6(){ digitalWrite( 9, LOW); }
void off7(){ digitalWrite(10, LOW); }
void off8(){ digitalWrite(11, LOW); }
void off9(){ digitalWrite(12, LOW); }
void off10(){ digitalWrite(13, LOW); }
int ledPins[] = { 4, 5, 6, 7, 8, 9,10,11,12,13 };
void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop()
{
on1(); on2(); on3(); on4(); on5(); on6(); on7(); on8(); on9(); on10();
delay(500);
off1(); off2(); off3(); off4(); off5(); off6(); off7(); off8(); off9(); off10();
delay(500);
on1(); on2(); on3(); on4(); on5(); on6(); on7(); on8(); on9(); on10();
delay(500);
off1(); off2(); off3(); off4(); off5(); off6(); off7(); off8(); off9(); off10();
delay(1000);
on1(); delay(100); on2(); delay(100); on3(); delay(100); on4(); delay(100); on5(); delay(100); on6(); delay(100); on7(); delay(100); on8(); delay(100); on9(); delay(100); on10();delay(100);
off1(); delay(100); off2(); delay(100); off3(); delay(100); off4(); delay(100); off5(); delay(100); off6(); delay(100); off7(); delay(100); off8(); delay(100); off9(); delay(100); off10();
delay(100);
on1(); delay(100); on2(); delay(100); on3(); delay(100); on4(); delay(100); on5(); delay(100); on6(); delay(100); on7(); delay(100); on8(); delay(100); on9(); delay(100); on10();delay(100);
off1(); delay(100); off2(); delay(100); off3(); delay(100); off4(); delay(100); off5(); delay(100); off6(); delay(100); off7(); delay(100); off8(); delay(100); off9(); delay(100); off10();
delay(1000);
on1(); delay(100); off1(); on2(); delay(100); off2(); on3(); delay(100); off3(); on4(); delay(100); off4(); on5(); delay(100); off5(); on6(); delay(100); off6(); on7(); delay(100); off7(); on8(); delay(100); off8(); on9(); delay(100); off9(); on10(); delay(100); off10();
delay(100);
on10(); delay(100); off10(); on9(); delay(100); off9(); on8(); delay(100); off8(); on7(); delay(100); off7(); on6(); delay(100); off6(); on5(); delay(100); off5(); on4(); delay(100); off4(); on3(); delay(100); off3(); on2(); delay(100); off2(); on1(); delay(100); off1();
delay(100);
on1(); delay(100); off1(); on2(); delay(100); off2(); on3(); delay(100); off3(); on4(); delay(100); off4(); on5(); delay(100); off5(); on6(); delay(100); off6(); on7(); delay(100); off7(); on8(); delay(100); off8(); on9(); delay(100); off9(); on10(); delay(100); off10();
delay(100);
on10(); delay(100); off10(); on9(); delay(100); off9(); on8(); delay(100); off8(); on7(); delay(100); off7(); on6(); delay(100); off6(); on5(); delay(100); off5(); on4(); delay(100); off4(); on3(); delay(100); off3(); on2(); delay(100); off2(); on1(); delay(100); off1();
delay(1000);
on1(); on10(); delay(100); on2(); on9(); off1(); off10(); delay(100); on3(); on8(); off2(); off9(); delay(100); on4(); on7(); off3(); off8(); delay(100); on5(); on6(); off4(); off7(); delay(100); off5(); off6(); delay(100);on5(); on6(); delay(100); on4(); on7(); off5(); off6(); delay(100); on3(); on8(); off4(); off7(); delay(100); on2(); on9(); off3(); off8(); delay(100); on1(); on10(); off2(); off9(); delay(100); off1(); off10();
delay(100);
on1(); on10(); delay(100); on2(); on9(); off1(); off10(); delay(100); on3(); on8(); off2(); off9(); delay(100); on4(); on7(); off3(); off8(); delay(100); on5(); on6(); off4(); off7(); delay(100); off5(); off6(); delay(100);on5(); on6(); delay(100); on4(); on7(); off5(); off6(); delay(100); on3(); on8(); off4(); off7(); delay(100); on2(); on9(); off3(); off8(); delay(100); on1(); on10(); off2(); off9(); delay(100); off1(); off10();
delay(1000);
}
void on1(){ digitalWrite( 4, HIGH); }
void on2(){ digitalWrite( 5, HIGH); }
void on3(){ digitalWrite( 6, HIGH); }
void on4(){ digitalWrite( 7, HIGH); }
void on5(){ digitalWrite( 8, HIGH); }
void on6(){ digitalWrite( 9, HIGH); }
void on7(){ digitalWrite(10, HIGH); }
void on8(){ digitalWrite(11, HIGH); }
void on9(){ digitalWrite(12, HIGH); }
void on10(){ digitalWrite(13, HIGH); }
void off1(){ digitalWrite( 4, LOW); }
void off2(){ digitalWrite( 5, LOW); }
void off3(){ digitalWrite( 6, LOW); }
void off4(){ digitalWrite( 7, LOW); }
void off5(){ digitalWrite( 8, LOW); }
void off6(){ digitalWrite( 9, LOW); }
void off7(){ digitalWrite(10, LOW); }
void off8(){ digitalWrite(11, LOW); }
void off9(){ digitalWrite(12, LOW); }
void off10(){ digitalWrite(13, LOW); }
Brak komentarzy:
Prześlij komentarz