#include "FastLED.h" #include #include #include LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); #define TRIGGER_PIN 13 #define ECHO_PIN 12 #define MAX_DISTANCE 50 #define NUM_STRIPS 3 #define NUM_LEDS_PER_STRIP 16 #define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP]; // NewPing setup of pins and maximum distance NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); //int db[] = {0,1,2,3,4,5,6,7,8,13,12,11,10,9,17,16,15,14}; // Radiant-D LED sequence int db[] = {5,6,4,7,3,8,2,9,1,10,0,11,15,12,14,13, 21,22,20,23,19,24,18,25,17,26,16,27,31,28,30,29, 33,34,32,35,47,36,46,37,45,38,44,39,43,40,42,41}; void setup() { delay(1000); // Power-up safety delay. FastLED.addLeds(leds, 0, NUM_LEDS_PER_STRIP); FastLED.addLeds(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP); FastLED.addLeds(leds, NUM_LEDS_PER_STRIP*2, NUM_LEDS_PER_STRIP); lcd.begin(16, 2); // 閃爍三次 for(int i = 0; i < 3; i++) { lcd.backlight(); // 開啟背光 delay(250); lcd.noBacklight(); // 關閉背光 delay(250); } lcd.backlight(); // 輸出初始化文字 lcd.setCursor(5, 0); // 設定游標位置在第一行行首 lcd.print("Gelid"); delay(1000); lcd.setCursor(3, 1); // 設定游標位置在第二行行首 lcd.print("Solutions"); delay(8000); } // *** REPLACE FROM HERE *** void loop() { delay(50); unsigned int distance = sonar.ping_cm(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Gelid Solutions"); lcd.setCursor(0, 1); lcd.print("distance: "); lcd.print(distance); lcd.print(" cm"); delay(1000); int metrosize = map(distance, 0, 50, 10, 32); // ---> here we call the effect function <--- meteorRain(0xff,0xff,0xff,metrosize, 64, true, 30); } // ---> here we define the effect function <--- // *** REPLACE TO HERE *** void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) { setAll(0,0,0); for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) { // fade brightness all LEDs one step for(int j=0; j5) ) { fadeToBlack(j, meteorTrailDecay ); } } // draw meteor for(int j = 0; j < meteorSize; j++) { if( ( i-j =0) ) { setPixel(i-j, red, green, blue); } } showStrip(); delay(SpeedDelay); } } void fadeToBlack(int ledNo, byte fadeValue) { // FastLED leds[db[ledNo]].fadeToBlackBy( fadeValue ); } //copy end here void showStrip() { // FastLED FastLED.show(); } void setPixel(int Pixel, byte red, byte green, byte blue) { // FastLED leds[db[Pixel]].r = red; leds[db[Pixel]].g = green; leds[db[Pixel]].b = blue; } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); }