#include #define LED_PIN1 13 #define LED_PIN2 12 #define NUM_LEDS1 31 #define NUM_LEDS2 23 CRGB leds1[NUM_LEDS1],leds2[NUM_LEDS2]; int i, musicScale[] = {523,587,659,698,784,880,988,1047}; int volume_value, gate_time = 10000, sw_old[] = {1,1}, sw_new[] = {0,0}, sw_eve[] = {0,0}; int timing[] = {0,0,0}, points[] = {0,0}, target, led_step = 2, vectors = 1; void setup() { for(i=9; i<11; i++) pinMode(i, INPUT); for(i=0; i<9; i++){ tone(11, musicScale[i]); delay(40); noTone(11); delay(60); } all_black(); sw_old[0] = digitalRead(10); delay(200); } void loop(){ volume_test(); if(++timing[2] > 50){ timing[2] = 0; sw_new[0] = digitalRead(10); if(sw_new[0] != sw_old[0]){ sw_old[0] = sw_new[0]; if(sw_new[0] == 0){ melody_again(4); if(points[0] == target){ Led1_set3(); melody_end(); all_black(); delay(1500); } else { points[1] = points[1] + led_step; Led2_set(points[1]-1, 1); if(points[1]>22){ for(i=40; i>0; i--){ tone(11, i*50); delay(50); } delay(1000); noTone(11); while(digitalRead(9) == HIGH){} all_black(); delay(1000); } } } } } if(++timing[1] > gate_time){ timing[1] = 0; Led1_set2(points[0], 8, 4); points[0] = points[0] + vectors; if(vectors == 1){ if(points[0] >= NUM_LEDS1){ points[0] = NUM_LEDS1 - 1; vectors = -1; melody_again(0); } } else{ if(points[0] < 0){ points[0] = 0; vectors = 1; melody_again(2); } } } } void volume_test(){ if(++timing[0] > 100){ timing[0] = 0; volume_value = analogRead(A0); gate_time = volume_value * 7 + 400; led_step = 2 + volume_value / 256; } } CRGB color_set(int color){ if(color<1 || color>8) return(CRGB::Black); switch(color){ case 1: return(CHSV(96, 255, 127)); // Red case 2: return(CHSV(0, 255, 127)); // Green case 3: return(CHSV(160, 255, 127)); // Blue case 4: return(CRGB::Gray); // White case 5: return(CHSV(60, 255, 127)); // Yellow case 6: return(CHSV(128, 255, 127)); // Pink case 7: return(CHSV(87, 255, 127)); // Ogange case 8: return(CHSV(random8(), 255, 127));// Random } } void Led1_set(int num, int color){ FastLED.addLeds(leds1, NUM_LEDS1); for(i=0; i(leds1, NUM_LEDS1); for(i=0; i(leds1, NUM_LEDS1); for(i=0; i 22) num = 22; FastLED.addLeds(leds2, NUM_LEDS2); for(i=0; i(leds1, NUM_LEDS1); for(i=0; i(leds2, NUM_LEDS2); for(i=0; i