Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Bogdan Apartment Code With Translation.
- #include "FastLED.h"
- #define NUM_LEDS 60
- #define DATA_PIN 11
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- int stikalo = 12; // a switch to select between the rainbow and the regular program
- int ledNeon1 = 4;
- int ledNeon2 = 5;
- int ledNeon3 = 6;
- int ledNeon4 = 7;
- int ledzunaj1 = 2;
- int ledzunaj2 = 3;
- int max_count = 80; // counter for the flicker table for neon lights
- int countTwo = 0;
- byte Flicker_table[] = { 10, 10, 20, 30, 30, 30, 40, 50, 60, 70, 80, 70, 70,
- 60, 60, 50, 50, 50, 60, 70, 80, 90, 100,
- 120,140,160,240,250,100,150,250,250,140,
- 240,230,220,100, 80,70,70, 70, 80, 80,
- 140,130,120,110,200,210,220,220,100, 90,
- 40, 30, 30, 30, 20, 10, 10 };
- boolean alreadyRun1 = false;
- boolean alreadyRun2 = false;
- boolean alreadyRun3 = false;
- int random_led;
- int cas;
- int barva;
- CRGB leds[NUM_LEDS];
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- void setup()
- {
- pinMode(stikalo, INPUT); // declare the switch pin as input
- pinMode(ledNeon1, OUTPUT);
- pinMode(ledNeon2, OUTPUT);
- pinMode(ledNeon3, OUTPUT);
- pinMode(ledNeon4, OUTPUT);
- pinMode(ledzunaj1, OUTPUT);
- pinMode(ledzunaj2, OUTPUT);
- // sanity check delay - allows reprogramming if accidently blowing power w/leds
- delay(2000);
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
- // Rainbow and its parameters
- delay(3000); // 3 second delay for recovery
- // tell FastLED about the LED strip configuration
- FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- }
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { rainbow};
- uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- void loop()
- {
- // if the switch is off it does execute the normal tower program
- if(digitalRead(stikalo) == LOW)
- {
- // read the input on analog pin 0:
- int sensorValue = analogRead(A6);
- // print out the value you read:
- //Serial.println(sensorValue);
- if (sensorValue <100)
- {
- digitalWrite(ledNeon4, LOW);
- digitalWrite(ledzunaj1, LOW);
- digitalWrite(ledzunaj2, LOW);
- dan();
- digitalWrite(ledNeon1, LOW);
- digitalWrite(ledNeon2, LOW);
- digitalWrite(ledNeon3, LOW);
- alreadyRun1 = false;
- alreadyRun2 = false;
- alreadyRun3 = false;
- }
- else
- {
- noc();
- neon();
- }
- }
- // if the switch is on, start the rainbow
- if(digitalRead(stikalo) == HIGH)
- {
- digitalWrite(ledNeon4, LOW);
- digitalWrite(ledzunaj1, LOW);
- digitalWrite(ledzunaj2, LOW);
- digitalWrite(ledNeon1, LOW);
- digitalWrite(ledNeon2, LOW);
- digitalWrite(ledNeon3, LOW);
- mavrica();
- }
- }
- // FUNKCIJE !!!!!!!!!!!!!!!!!1
- //the first main function for the neon light, it checks to see if any have already failed and if not, the first second and third neon functions
- void neon()
- {
- if (alreadyRun1 == false)
- {
- neon1();
- }
- if (alreadyRun2 == false)
- {
- neon2();
- }
- if (alreadyRun3 == false)
- {
- neon3();
- }
- delay(500);
- digitalWrite(ledzunaj1, HIGH);
- digitalWrite(ledzunaj2, HIGH);
- }
- //function for the first neon
- void neon1(){
- alreadyRun1 = true;
- delay(30);
- for ( int i=0; i <= 150; i++) { // This for loop runs until the flicker table finishes
- analogWrite(ledNeon1, Flicker_table[countTwo]);
- countTwo++;
- if(countTwo > max_count ){
- countTwo = 0; // Helps makes sure our next flicker doesnt start in an arbitrary place on the table
- }
- delay(20); // the delay for our flicker, make it faster to to make it flicker a little more violently
- digitalWrite(ledNeon1, HIGH);
- }
- }
- // function for second neon
- void neon2(){
- alreadyRun2 = true;
- delay(30);
- for ( int i=0; i <= 150; i++) { // This for loop runs untill the flicker table finishes
- analogWrite(ledNeon2, Flicker_table[countTwo]);
- countTwo++;
- if(countTwo > max_count ){
- countTwo = 0; // Helps makes sure our next flicker doesnt start in an arbitrary place on the table
- }
- delay(20); // the delay for our flicker, make it faster to to make it flicker a little more violently
- digitalWrite(ledNeon2, HIGH);
- }
- }
- // Function for the third and fourth neon lights
- void neon3(){
- alreadyRun3 = true;
- delay(30);
- for ( int i=0; i <= 150; i++) { // This for loop runs untill the flicker table finishes
- analogWrite(ledNeon3, Flicker_table[countTwo]);
- analogWrite(ledNeon4, Flicker_table[countTwo]);
- countTwo++;
- if(countTwo > max_count ){
- countTwo = 0; // Helps makes sure our next flicker doesnt start in an arbitrary place on the table
- }
- delay(15); // the delay for our flicker, make it faster to to make it flicker a little more violently
- digitalWrite(ledNeon3, HIGH);
- digitalWrite(ledNeon4, HIGH);
- }
- }
- void dan()
- #define BRIGHTNESS 100
- {
- FastLED.setBrightness(BRIGHTNESS);
- //prižiganje
- barva = random (200,255);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- cas = random (100,1000);
- leds[random_led] = CRGB(180,255,barva);
- FastLED.show();
- delay(cas);
- //ugašanje 1
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 2
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 3
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 4
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 5
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 6
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 7
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 8
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 9
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- //ugašanje 10
- cas = random (10,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- }
- void noc()
- #define BRIGHTNESS 50
- {
- FastLED.setBrightness(BRIGHTNESS);
- //prižiganje 1
- barva = random (200,255);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- cas = random (100,2000);
- leds[random_led] = CRGB(180,255,barva);
- FastLED.show();
- delay(cas);
- //prižiganje 2
- barva = random (100,255);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- cas = random (100,1000);
- leds[random_led] = CRGB(255,255,barva);
- FastLED.show();
- delay(cas);
- //ugašanje
- cas = random (100,1000);
- random_led = random(0,60); //the first number is the initial LED and the second is the last LED
- leds[random_led] = CRGB(0,0,0);
- delay(cas);
- }
- void mavrica() //rainbow
- {
- #define BRIGHTNESS 100
- #define FRAMES_PER_SECOND 10000
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- // Call the current pattern function once, updating the 'leds' array
- gPatterns[gCurrentPatternNumber]();
- // send the 'leds' array out to the actual LED strip
- FastLED.show();
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- // do some periodic updates
- EVERY_N_MILLISECONDS( 3 ) { gHue++; } // slowly cycle the "base color" through the rainbow
- //EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
- }
- void rainbow()
- {
- // FastLED's built-in rainbow generator
- fill_rainbow( leds, NUM_LEDS, gHue, 4);
- }
Advertisement
Add Comment
Please, Sign In to add comment