kartonman

Bogdan Apartment Code

Aug 31st, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. Bogdan Apartment Code With Translation.
  2.  
  3. #include "FastLED.h"
  4.  
  5. #define NUM_LEDS 60
  6. #define DATA_PIN 11
  7. #define LED_TYPE WS2812B
  8. #define COLOR_ORDER GRB
  9.  
  10. int stikalo = 12; // a switch to select between the rainbow and the regular program
  11. int ledNeon1 = 4;
  12. int ledNeon2 = 5;
  13. int ledNeon3 = 6;
  14. int ledNeon4 = 7;
  15. int ledzunaj1 = 2;
  16. int ledzunaj2 = 3;
  17. int max_count = 80; // counter for the flicker table for neon lights
  18. int countTwo = 0;
  19. byte Flicker_table[] = { 10, 10, 20, 30, 30, 30, 40, 50, 60, 70, 80, 70, 70,
  20. 60, 60, 50, 50, 50, 60, 70, 80, 90, 100,
  21. 120,140,160,240,250,100,150,250,250,140,
  22. 240,230,220,100, 80,70,70, 70, 80, 80,
  23. 140,130,120,110,200,210,220,220,100, 90,
  24. 40, 30, 30, 30, 20, 10, 10 };
  25. boolean alreadyRun1 = false;
  26. boolean alreadyRun2 = false;
  27. boolean alreadyRun3 = false;
  28. int random_led;
  29. int cas;
  30. int barva;
  31. CRGB leds[NUM_LEDS];
  32. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  33.  
  34.  
  35. void setup()
  36. {
  37. pinMode(stikalo, INPUT); // declare the switch pin as input
  38. pinMode(ledNeon1, OUTPUT);
  39. pinMode(ledNeon2, OUTPUT);
  40. pinMode(ledNeon3, OUTPUT);
  41. pinMode(ledNeon4, OUTPUT);
  42. pinMode(ledzunaj1, OUTPUT);
  43. pinMode(ledzunaj2, OUTPUT);
  44. // sanity check delay - allows reprogramming if accidently blowing power w/leds
  45. delay(2000);
  46. FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  47.  
  48. // Rainbow and its parameters
  49. delay(3000); // 3 second delay for recovery
  50. // tell FastLED about the LED strip configuration
  51. FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  52. }
  53. // List of patterns to cycle through. Each is defined as a separate function below.
  54. typedef void (*SimplePatternList[])();
  55. SimplePatternList gPatterns = { rainbow};
  56. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  57. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  58.  
  59.  
  60. void loop()
  61. {
  62. // if the switch is off it does execute the normal tower program
  63. if(digitalRead(stikalo) == LOW)
  64. {
  65. // read the input on analog pin 0:
  66. int sensorValue = analogRead(A6);
  67. // print out the value you read:
  68. //Serial.println(sensorValue);
  69.  
  70. if (sensorValue <100)
  71. {
  72. digitalWrite(ledNeon4, LOW);
  73. digitalWrite(ledzunaj1, LOW);
  74. digitalWrite(ledzunaj2, LOW);
  75. dan();
  76. digitalWrite(ledNeon1, LOW);
  77. digitalWrite(ledNeon2, LOW);
  78. digitalWrite(ledNeon3, LOW);
  79. alreadyRun1 = false;
  80. alreadyRun2 = false;
  81. alreadyRun3 = false;
  82. }
  83. else
  84. {
  85. noc();
  86. neon();
  87. }
  88. }
  89. // if the switch is on, start the rainbow
  90. if(digitalRead(stikalo) == HIGH)
  91. {
  92. digitalWrite(ledNeon4, LOW);
  93. digitalWrite(ledzunaj1, LOW);
  94. digitalWrite(ledzunaj2, LOW);
  95. digitalWrite(ledNeon1, LOW);
  96. digitalWrite(ledNeon2, LOW);
  97. digitalWrite(ledNeon3, LOW);
  98. mavrica();
  99. }
  100. }
  101.  
  102.  
  103. // FUNKCIJE !!!!!!!!!!!!!!!!!1
  104. //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
  105. void neon()
  106. {
  107. if (alreadyRun1 == false)
  108. {
  109. neon1();
  110. }
  111. if (alreadyRun2 == false)
  112. {
  113. neon2();
  114. }
  115. if (alreadyRun3 == false)
  116. {
  117. neon3();
  118. }
  119. delay(500);
  120. digitalWrite(ledzunaj1, HIGH);
  121. digitalWrite(ledzunaj2, HIGH);
  122. }
  123. //function for the first neon
  124. void neon1(){
  125. alreadyRun1 = true;
  126. delay(30);
  127. for ( int i=0; i <= 150; i++) { // This for loop runs until the flicker table finishes
  128. analogWrite(ledNeon1, Flicker_table[countTwo]);
  129. countTwo++;
  130. if(countTwo > max_count ){
  131. countTwo = 0; // Helps makes sure our next flicker doesnt start in an arbitrary place on the table
  132. }
  133. delay(20); // the delay for our flicker, make it faster to to make it flicker a little more violently
  134. digitalWrite(ledNeon1, HIGH);
  135. }
  136. }
  137. // function for second neon
  138. void neon2(){
  139. alreadyRun2 = true;
  140. delay(30);
  141. for ( int i=0; i <= 150; i++) { // This for loop runs untill the flicker table finishes
  142. analogWrite(ledNeon2, Flicker_table[countTwo]);
  143. countTwo++;
  144. if(countTwo > max_count ){
  145. countTwo = 0; // Helps makes sure our next flicker doesnt start in an arbitrary place on the table
  146. }
  147. delay(20); // the delay for our flicker, make it faster to to make it flicker a little more violently
  148. digitalWrite(ledNeon2, HIGH);
  149. }
  150. }
  151. // Function for the third and fourth neon lights
  152. void neon3(){
  153. alreadyRun3 = true;
  154. delay(30);
  155. for ( int i=0; i <= 150; i++) { // This for loop runs untill the flicker table finishes
  156. analogWrite(ledNeon3, Flicker_table[countTwo]);
  157. analogWrite(ledNeon4, Flicker_table[countTwo]);
  158. countTwo++;
  159. if(countTwo > max_count ){
  160. countTwo = 0; // Helps makes sure our next flicker doesnt start in an arbitrary place on the table
  161. }
  162. delay(15); // the delay for our flicker, make it faster to to make it flicker a little more violently
  163. digitalWrite(ledNeon3, HIGH);
  164. digitalWrite(ledNeon4, HIGH);
  165. }
  166. }
  167. void dan()
  168. #define BRIGHTNESS 100
  169. {
  170. FastLED.setBrightness(BRIGHTNESS);
  171. //prižiganje
  172. barva = random (200,255);
  173. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  174. cas = random (100,1000);
  175. leds[random_led] = CRGB(180,255,barva);
  176. FastLED.show();
  177. delay(cas);
  178. //ugašanje 1
  179. cas = random (10,1000);
  180. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  181. leds[random_led] = CRGB(0,0,0);
  182. delay(cas);
  183. //ugašanje 2
  184. cas = random (10,1000);
  185. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  186. leds[random_led] = CRGB(0,0,0);
  187. delay(cas);
  188. //ugašanje 3
  189. cas = random (10,1000);
  190. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  191. leds[random_led] = CRGB(0,0,0);
  192. delay(cas);
  193. //ugašanje 4
  194. cas = random (10,1000);
  195. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  196. leds[random_led] = CRGB(0,0,0);
  197. delay(cas);
  198. //ugašanje 5
  199. cas = random (10,1000);
  200. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  201. leds[random_led] = CRGB(0,0,0);
  202. delay(cas);
  203. //ugašanje 6
  204. cas = random (10,1000);
  205. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  206. leds[random_led] = CRGB(0,0,0);
  207. delay(cas);
  208. //ugašanje 7
  209. cas = random (10,1000);
  210. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  211. leds[random_led] = CRGB(0,0,0);
  212. delay(cas);
  213. //ugašanje 8
  214. cas = random (10,1000);
  215. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  216. leds[random_led] = CRGB(0,0,0);
  217. delay(cas);
  218. //ugašanje 9
  219. cas = random (10,1000);
  220. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  221. leds[random_led] = CRGB(0,0,0);
  222. delay(cas);
  223. //ugašanje 10
  224. cas = random (10,1000);
  225. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  226. leds[random_led] = CRGB(0,0,0);
  227. delay(cas);
  228. }
  229. void noc()
  230. #define BRIGHTNESS 50
  231. {
  232. FastLED.setBrightness(BRIGHTNESS);
  233. //prižiganje 1
  234. barva = random (200,255);
  235. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  236. cas = random (100,2000);
  237. leds[random_led] = CRGB(180,255,barva);
  238. FastLED.show();
  239. delay(cas);
  240. //prižiganje 2
  241. barva = random (100,255);
  242. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  243. cas = random (100,1000);
  244. leds[random_led] = CRGB(255,255,barva);
  245. FastLED.show();
  246. delay(cas);
  247. //ugašanje
  248. cas = random (100,1000);
  249. random_led = random(0,60); //the first number is the initial LED and the second is the last LED
  250. leds[random_led] = CRGB(0,0,0);
  251. delay(cas);
  252. }
  253. void mavrica() //rainbow
  254. {
  255. #define BRIGHTNESS 100
  256. #define FRAMES_PER_SECOND 10000
  257. // set master brightness control
  258. FastLED.setBrightness(BRIGHTNESS);
  259. // Call the current pattern function once, updating the 'leds' array
  260. gPatterns[gCurrentPatternNumber]();
  261. // send the 'leds' array out to the actual LED strip
  262. FastLED.show();
  263. // insert a delay to keep the framerate modest
  264. FastLED.delay(1000/FRAMES_PER_SECOND);
  265. // do some periodic updates
  266. EVERY_N_MILLISECONDS( 3 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  267. //EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  268. }
  269. void rainbow()
  270. {
  271. // FastLED's built-in rainbow generator
  272. fill_rainbow( leds, NUM_LEDS, gHue, 4);
  273. }
  274.  
Advertisement
Add Comment
Please, Sign In to add comment