שיעור 10 - לולאות

ברוכים הבאים לשיעור העשירי!

השיעור מורכב מסדרה של סרטונים, צפו בהם לפי הסדר.

תהנו 🙂

חלק 1: הקדמה

חלק 2: כתובות הלדים במסך

העתיקו את הקוד מקופסה זו:

  #include <FastLED.h>
  #define NUM_LEDS 16
  #define DATA_PIN 33
  CRGB leds[NUM_LEDS];

  int counter = 0;
 
void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  leds[0] = CRGB::Blue;
  FastLED.show();
}

void loop() {

}
 

חלק 3: לולאת While

העתיקו את הקוד מקופסה זו:

  #include <FastLED.h>
  #define NUM_LEDS 16
  #define DATA_PIN 33
  CRGB leds[NUM_LEDS];

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  leds[0] = CRGB::Blue;
  leds[1] = CRGB::Blue;
  FastLED.show();

}

void loop() {

}
 

הקוד של הלולאה

  #include <FastLED.h>
  #define NUM_LEDS 16
  #define DATA_PIN 33
  CRGB leds[NUM_LEDS];

  int counter = 0;
 
void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  while (counter<16)
  {
    leds[counter] = CRGB::Blue;
    FastLED.show();
    delay(1000);
    counter = counter +1;
  }


}

void loop() {

}
 

חלק 4: משימת הדלקה וכיבוי!

  #include <FastLED.h>
  #define NUM_LEDS 16
  #define DATA_PIN 33
  CRGB leds[NUM_LEDS];

  int counter = 0;
 
void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  while (counter<16)
  {
    leds[counter] = CRGB::Blue;
    FastLED.show();
    delay(500);
    counter = counter +1;
  }
  while (counter>=0)
  {
    leds[counter] = CRGB::Black;
    FastLED.show();
    delay(500);
    counter = counter - 1;
  }

}
 

חלק 5: לולאה בתוך לולאה

  #include <FastLED.h>
  #define NUM_LEDS 16
  #define DATA_PIN 33
  CRGB leds[NUM_LEDS];

  int counter = 0;
  int new_counter = 0;
 
void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  while (new_counter<4)
  {
    counter = 0;
    new_counter++;
    //LEDs ON
    while (counter<16)
    {
      leds[counter] = CRGB::Blue;
      FastLED.show();
      delay(50);
      counter = counter +1;
    }
   
    //LEDs OFF
    counter = 15;
    while (counter>=0)
    {
      leds[counter] = CRGB::Black;
      FastLED.show();
      delay(50);
      counter = counter - 1;
    }
  }
}

void loop() {

} 

חלק 6: המשימה - דגל שחמט

  #include <FastLED.h>
  #define NUM_LEDS 16
  #define DATA_PIN 33
  CRGB leds[NUM_LEDS];

  int counter = 0;
 
void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  //LEDs ON
  //Paint 0,2,4,6,8,10,12,14,16
  while (counter<16)
  {
    leds[counter] = CRGB::Blue;
    FastLED.show();
    delay(50);
    counter = counter + 2;
  }

  counter = 1;
  //Paint 1,3,5,7,9,11,13,15
  while (counter<16)
  {
    leds[counter] = CRGB::Red;
    FastLED.show();
    delay(50);
    counter = counter + 2;
  }
 
}

void loop() {

}