Advertisement
Cidius

<c> computer lighting mod

Dec 2nd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.10 KB | None | 0 0
  1. //This is a computer lighting program, it controls 12 fan mounted LED's plus 30 window mounted LEDs on a strip called WS2812-B's, it's controlled by an arduino nano. Notes about the program. White is all values equal at about 15% power, Light has an exponential relationship, and so any gradients appear hyperbolic, lowering the numbers to so low makes gradients appear somewhat linear. Basically this display will show 2 colours at once in various forms. There are 4 colour presets, and 4 buttons. the first 2 colours are custom and saved into EEPROM, 3rd colour is white, 4th is black/off. Button 1 is basically imagined to have a "<" symbol on it, 2 is "c" and 3 is ">", hitting any 2 buttons allows us to customise the colours, hitting < makes it less white, and > makes it more white, c will pause and then hitting < will save into position 1 and > will save into position 2. Button 4 turns everything off and cycles until button 2 is pressed (I wanted to use 4 but it became finicky with release times). The program mostly works by shuffling around arrays and as such a few global arrays exist. all functions work and compiling is fine. The program uses approx 60% of storage, 0.5% of EEPROM, Globals consume 25% of RAM. The most RAM intense function should be 'Attack()' [I named things the first thing that came to my mind to describe things, changing my mind might just confuse me down the line, don't mock me]. Only issue is if there's more ways to make it more efficient, or I have some bad logic.
  2.  
  3.  
  4.  
  5.  
  6. #include <Arduino.h>
  7. #include<Tlc5940.h>
  8. #include <FastLED.h>
  9. #include <EEPROM.h>
  10. #define NUM_LEDS 30
  11. #define DATA_PIN 8
  12. const int button1 = 4;
  13. const int button2 = 5;
  14. const int button3 = 6;
  15. const int button4 = 7;
  16. CRGB leds[NUM_LEDS];
  17. int first = 0; //these three ints determine the colours put into a mode and what colours that mode will make
  18. int second = 3;
  19. int mode = 1;
  20. int RedSelect[] = {0, 0, 30, 0};
  21. int GreenSelect[] = {0, 0, 30, 0};
  22. int BlueSelect[] = {0, 0, 30, 0}; // initiallising the 3 arrays that determine the 4 colours, 3 and 4 are defaults, 1 and 2 get set in setup/colourset.
  23. int Primary[3];
  24. int Secondary[3];
  25. int RedOut[42] = { 0 };
  26. int BlueOut[42] = { 0 };
  27. int GreenOut[42] = { 0 };
  28.  
  29. void setup() {
  30. FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  31. pinMode(button1, INPUT);
  32. pinMode(button2, INPUT);
  33. pinMode(button3, INPUT);
  34. pinMode(button4, INPUT);
  35. RedSelect[0] = EEPROM.read(1);
  36. GreenSelect[0] = EEPROM.read(2);
  37. BlueSelect[0] = EEPROM.read(3);
  38. RedSelect[1] = EEPROM.read(4);
  39. GreenSelect[1] = EEPROM.read(5);
  40. BlueSelect[1] = EEPROM.read(6);
  41. Tlc.init(0);
  42. }
  43.  
  44. void loop() {
  45.  
  46. Primary[0] = RedSelect[first];
  47. Secondary[0] = RedSelect[second]; //associates values with arrays to define colour mode
  48. Primary[1] = GreenSelect[first];
  49. Secondary[1] = GreenSelect[second];
  50. Primary[2] = BlueSelect[first];
  51. Secondary[2] = BlueSelect[second];
  52.  
  53. int action = 0;
  54.  
  55. switch ( mode ) { //mode control menu
  56. case 1:
  57. action = Static();
  58. break;
  59. case 2:
  60. action = HoriGrad();
  61. break;
  62. case 3:
  63. action = VertiGrad();
  64. break;
  65. case 4:
  66. action = Pulse();
  67. break;
  68. case 5:
  69. action = Attack();
  70. break;
  71. case 6:
  72. action = Chase();
  73. break;
  74. }
  75. delay(300);
  76. switch ( action ) { //the button controls
  77. case 0:
  78. break;
  79. case 1:
  80. mode--;
  81. if (mode <= 0) {
  82. mode = 6;
  83. }
  84. break;
  85. case 2:
  86. colourhop();
  87. break;
  88. case 3:
  89. colourset();
  90. break;
  91. case 4:
  92. mode++;
  93. if (mode > 6) {
  94. mode = 1;
  95. } //menu loop
  96. break;
  97. case 5:
  98. colourset();
  99. break;
  100. case 6:
  101. colourset();
  102. break;
  103. case 7:
  104. break;
  105. colourset();
  106. default:
  107. break;
  108. }
  109.  
  110. }
  111.  
  112. void colourset() { //cycles through colours til one is selected completed
  113. int reddir = 1;
  114. int greendir = 0;
  115. int bluedir = -1;
  116. int i = 0;
  117. int red = 220;
  118. int green = 0;
  119. int blue = 0;
  120. boolean flag = true;
  121. int swap = 0;
  122. do {
  123. if (red == 220) {
  124. reddir = -1;
  125. bluedir = 1;
  126. greendir = 0;
  127. blue = 0;
  128. green = 0;
  129. }
  130. if (blue == 220) {
  131. bluedir = -1;
  132. greendir = 1;
  133. red = 0;
  134. green = 0;
  135. reddir = 0;
  136. }
  137. if (green == 220) {
  138. greendir = -1;
  139. reddir = 1;
  140. red = 0;
  141. blue = 0;
  142. bluedir = 0;
  143. }
  144. red = red + reddir;
  145. blue = blue + bluedir;
  146. green = green + greendir;
  147. int outred = i + red;
  148. int outblue = i + blue;
  149. int outgreen = i + green;
  150. GlobalSet(outred, outgreen, outblue);
  151. delay(10);
  152. int operate = buttoncheck();
  153. if (operate == 1 && i >= 0) {
  154. i = i - 1;
  155. delay(40);
  156. }
  157. if (operate == 4 && i <= 30) {
  158. i++;
  159. delay(40);
  160. }
  161. if (operate == 7) {
  162. flag = false;
  163. }
  164. if (operate == 2) {
  165. delay(350);
  166. boolean repflag = true;
  167. do {
  168. int choice = buttoncheck();
  169. if (choice == 1) {
  170. repflag = false;
  171. flag = false;
  172. EEPROM.write(1, outred);
  173. EEPROM.write(2, outgreen);
  174. EEPROM.write(3, outblue);
  175. RedSelect[0] = outred;
  176. GreenSelect[0] = outgreen;
  177. BlueSelect[0] = outblue;
  178. first = 0;
  179. second = 2;
  180. }
  181. if (choice == 4) {
  182. repflag = false;
  183. flag = false;
  184. EEPROM.write(4, outred);
  185. EEPROM.write(5, outgreen);
  186. EEPROM.write(6, outblue);
  187. RedSelect[1] = outred;
  188. GreenSelect[1] = outgreen;
  189. BlueSelect[1] = outblue;
  190. first = 1;
  191. second = 2;
  192. }
  193. if (choice == 2) {
  194. repflag = false;
  195. }
  196. delay(500);
  197. } while (repflag = true);
  198. }
  199. } while (flag = true);
  200. return;
  201. }
  202.  
  203.  
  204. int Static() { //outputs a static colour into every value
  205. int out = 0;
  206. GlobalSet(Primary[0], Primary [1], Primary [2]);
  207. do {
  208. out = buttoncheck();
  209. delay(400);
  210. } while (out == 0);
  211. return (out);
  212. }
  213.  
  214. int HoriGrad() { //horizontal gradient - completed
  215.  
  216. int AllReds[] = {Primary[0], Primary[0] * 0.9 + Secondary[0] * 0.1, Primary[0] * 0.8 + Secondary[0] * 0.2, Primary[0] * 0.7 + Secondary[0] * 0.3, Primary[0] * 0.6 + Secondary[0] * 0.4, Primary[0] * 0.5 + Secondary[0] * 0.5, Primary[0] * 0.4 + Secondary[0] * 0.6, Primary[0] * 0.3 + Secondary[0] * 0.7, Primary[0] * 0.2 + Secondary[0] * 0.8, Primary[0] * 0.1 + Secondary[0] * 0.9,
  217. Secondary[0]
  218. };
  219. int AllGreens[] = {Primary[1], Primary[1] * 0.9 + Secondary[1] * 0.1, Primary[1] * 0.8 + Secondary[1] * 0.2, Primary[1] * 0.7 + Secondary[1] * 0.3, Primary[1] * 0.6 + Secondary[1] * 0.4, Primary[1] * 0.5 + Secondary[1] * 0.5, Primary[1] * 0.4 + Secondary[1] * 0.6, Primary[1] * 0.3 + Secondary[1] * 0.7, Primary[1] * 0.2 + Secondary[1] * 0.8, Primary[1] * 0.1 + Secondary[1] * 0.9,
  220. Secondary[1]
  221. };
  222. int AllBlues[] = {Primary[2], Primary[2] * 0.9 + Secondary[2] * 0.1, Primary[2] * 0.8 + Secondary[2] * 0.2, Primary[2] * 0.7 + Secondary[2] * 0.3, Primary[2] * 0.6 + Secondary[2] * 0.4, Primary[2] * 0.5 + Secondary[2] * 0.5, Primary[2] * 0.4 + Secondary[2] * 0.6, Primary[2] * 0.3 + Secondary[2] * 0.7, Primary[2] * 0.2 + Secondary[2] * 0.8, Primary[2] * 0.1 + Secondary[2] * 0.9,
  223. Secondary[2]
  224. };
  225.  
  226. int tempyRed[42] = {AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[1], AllReds[2], AllReds[3], AllReds[4], AllReds[5], AllReds[5], AllReds[6], AllReds[7], AllReds[8], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[8], AllReds[7], AllReds[6], AllReds[5], AllReds[5], AllReds[4], AllReds[3], AllReds[2], AllReds[1], AllReds[0]};
  227. int tempyGreen[42] = {AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[1], AllGreens[2], AllGreens[3], AllGreens[4], AllGreens[5], AllGreens[5], AllGreens[6], AllGreens[7], AllGreens[8], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[8], AllGreens[7], AllGreens[6], AllGreens[5], AllGreens[5], AllGreens[4], AllGreens[3], AllGreens[2], AllGreens[1], AllGreens[0]};
  228. int tempyBlue[42] = {AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[1], AllBlues[2], AllBlues[3], AllBlues[4], AllBlues[5], AllBlues[5], AllBlues[6], AllBlues[7], AllBlues[8], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[8], AllBlues[7], AllBlues[6], AllBlues[5], AllBlues[5], AllBlues[4], AllBlues[3], AllBlues[2], AllBlues[1], AllBlues[0]};
  229. for (int count = 0; count < 42; count++) {
  230. RedOut[count] = tempyRed[count];
  231. GreenOut[count] = tempyGreen[count];
  232. BlueOut[count] = tempyBlue[count];
  233. }
  234. DisplayArrays();
  235. int out = 0;
  236. do {
  237. out = buttoncheck();
  238. delay(100);
  239. } while (out == 0);
  240. return (out);
  241. }
  242.  
  243. int Chase() {
  244. GlobalSet(Secondary[0], Secondary[1], Secondary[2]);
  245. RedOut[0] = Primary[0];
  246. GreenOut[0] = Primary[1];
  247. BlueOut[0] = Primary[2];
  248. int out = 0;
  249. do {
  250. DisplayArrays();
  251. int swap[3] = {RedOut[41], GreenOut[41], BlueOut[41]};
  252. for (int count = 41; count > 0; count--) {
  253. RedOut[count] = RedOut[count - 1];
  254. GreenOut[count] = GreenOut[count - 1];
  255. BlueOut[count] = BlueOut[count - 1];
  256. }
  257. RedOut[0] = swap[0];
  258. GreenOut[0] = swap[1];
  259. BlueOut[0] = swap[2];
  260. delay(50);
  261. out = buttoncheck();
  262. } while (out == 0);
  263. return (out);
  264. }
  265.  
  266. int VertiGrad() { //verticle gradient - completed
  267.  
  268. int AllReds[] = {Primary[0], Primary[0] * 0.9 + Secondary[0] * 0.1, Primary[0] * 0.8 + Secondary[0] * 0.2, Primary[0] * 0.7 + Secondary[0] * 0.3, Primary[0] * 0.6 + Secondary[0] * 0.4, Primary[0] * 0.5 + Secondary[0] * 0.5, Primary[0] * 0.4 + Secondary[0] * 0.6, Primary[0] * 0.3 + Secondary[0] * 0.7, Primary[0] * 0.2 + Secondary[0] * 0.8, Primary[0] * 0.1 + Secondary[0] * 0.9,
  269. Secondary[0]
  270. };
  271. int AllGreens[] = {Primary[1], Primary[1] * 0.9 + Secondary[1] * 0.1, Primary[1] * 0.8 + Secondary[1] * 0.2, Primary[1] * 0.7 + Secondary[1] * 0.3, Primary[1] * 0.6 + Secondary[1] * 0.4, Primary[1] * 0.5 + Secondary[1] * 0.5, Primary[1] * 0.4 + Secondary[1] * 0.6, Primary[1] * 0.3 + Secondary[1] * 0.7, Primary[1] * 0.2 + Secondary[1] * 0.8, Primary[1] * 0.1 + Secondary[1] * 0.9,
  272. Secondary[1]
  273. };
  274. int AllBlues[] = {Primary[2], Primary[2] * 0.9 + Secondary[2] * 0.1, Primary[2] * 0.8 + Secondary[2] * 0.2, Primary[2] * 0.7 + Secondary[2] * 0.3, Primary[2] * 0.6 + Secondary[2] * 0.4, Primary[2] * 0.5 + Secondary[2] * 0.5, Primary[2] * 0.4 + Secondary[2] * 0.6, Primary[2] * 0.3 + Secondary[2] * 0.7, Primary[2] * 0.2 + Secondary[2] * 0.8, Primary[2] * 0.1 + Secondary[2] * 0.9,
  275. Secondary[2]
  276. };
  277.  
  278. int tempyRed[42] = {AllReds[1], AllReds[2], AllReds[3], AllReds[4], AllReds[5], AllReds[6], AllReds[7], AllReds[8], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[8], AllReds[8], AllReds[8], AllReds[8], AllReds[7], AllReds[6], AllReds[5], AllReds[4], AllReds[3], AllReds[2], AllReds[1], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0]};
  279. int tempyGreen[42] = {AllGreens[1], AllGreens[2], AllGreens[3], AllGreens[4], AllGreens[5], AllGreens[6], AllGreens[7], AllGreens[8], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[8], AllGreens[8], AllGreens[8], AllGreens[8], AllGreens[7], AllGreens[6], AllGreens[5], AllGreens[4], AllGreens[3], AllGreens[2], AllGreens[1], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0]};
  280. int tempyBlue[42] = {AllBlues[1], AllBlues[2], AllBlues[3], AllBlues[4], AllBlues[5], AllBlues[6], AllBlues[7], AllBlues[8], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[8], AllBlues[8], AllBlues[8], AllBlues[8], AllBlues[7], AllBlues[6], AllBlues[5], AllBlues[4], AllBlues[3], AllBlues[2], AllBlues[1], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0]};
  281. for (int count = 0; count < 42; count++) {
  282. RedOut[count] = tempyRed[count];
  283. GreenOut[count] = tempyGreen[count];
  284. BlueOut[count] = tempyBlue[count];
  285. }
  286. DisplayArrays();
  287. int out = 0;
  288. do {
  289. out = buttoncheck();
  290. delay(100);
  291. } while (out == 0);
  292. return (out);
  293. }
  294.  
  295. int Attack() { //horigrad moving - Completed
  296.  
  297. int AllReds[10] = {Primary[0], Primary[0] * 0.75 + Secondary[0] * 0.25, Primary[0] * 0.5 + Secondary[0] * 0.5, Primary[0] * 0.25 + Secondary[0] * 0.75, Secondary[0], Secondary[0], Secondary[0], Secondary[0], Secondary[0], Secondary[0]};
  298. int AllGreens[10] = {Primary[1], Primary[1] * 0.75 + Secondary[1] * 0.25, Primary[1] * 0.5 + Secondary[1] * 0.5, Primary[1] * 0.25 + Secondary[1] * 0.75, Secondary[1], Secondary[1], Secondary[1], Secondary[1], Secondary[1], Secondary[1]};
  299. int AllBlues[10] = {Primary[2], Primary[2] * 0.75 + Secondary[2] * 0.25, Primary[2] * 0.5 + Secondary[2] * 0.5, Primary[2] * 0.25 + Secondary[2] * 0.75, Secondary[2], Secondary[2], Secondary[2], Secondary[2], Secondary[2], Secondary[2]};
  300. int out = 0;
  301. do {
  302. int tempyRed[42] = {AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[0], AllReds[1], AllReds[2], AllReds[3], AllReds[4], AllReds[5], AllReds[5], AllReds[6], AllReds[7], AllReds[8], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[9], AllReds[8], AllReds[7], AllReds[6], AllReds[5], AllReds[5], AllReds[4], AllReds[3], AllReds[2], AllReds[1], AllReds[0]};
  303. int tempyGreen[42] = {AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[0], AllGreens[1], AllGreens[2], AllGreens[3], AllGreens[4], AllGreens[5], AllGreens[5], AllGreens[6], AllGreens[7], AllGreens[8], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[9], AllGreens[8], AllGreens[7], AllGreens[6], AllGreens[5], AllGreens[5], AllGreens[4], AllGreens[3], AllGreens[2], AllGreens[1], AllGreens[0]};
  304. int tempyBlue[42] = {AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[0], AllBlues[1], AllBlues[2], AllBlues[3], AllBlues[4], AllBlues[5], AllBlues[5], AllBlues[6], AllBlues[7], AllBlues[8], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[9], AllBlues[8], AllBlues[7], AllBlues[6], AllBlues[5], AllBlues[5], AllBlues[4], AllBlues[3], AllBlues[2], AllBlues[1], AllBlues[0]};
  305.  
  306. for (int count = 0; count < 42; count++) {
  307. RedOut[count] = tempyRed[count];
  308. GreenOut[count] = tempyGreen[count];
  309. BlueOut[count] = tempyBlue[count];
  310. }
  311.  
  312. int swap[3] = {AllReds[9], AllGreens[9], AllBlues[9]};
  313. for (int count = 9; count > 0; count--) {
  314. AllReds[count] = AllReds[count - 1];
  315. AllGreens[count] = AllGreens[count - 1];
  316. AllBlues[count] = AllBlues[count - 1];
  317. }
  318.  
  319. AllReds[0] = swap[0];
  320. AllGreens[0] = swap[1];
  321. AllBlues[0] = swap[2];
  322. DisplayArrays();
  323. out = buttoncheck();
  324. delay(40);
  325. } while (out == 0);
  326. return (out);
  327. }
  328.  
  329. int Pulse() { //swaps between the two colours back and fourt in incriments -Completed
  330. int out = 0;
  331. int count = 0;
  332. int invert = 0;
  333. boolean Rising = true;
  334. float tempr = 0;
  335. float tempg = 0;
  336. float tempb = 0;
  337. int r, b, g;
  338.  
  339. do {
  340. if (Rising) {
  341. if (count < 100) {
  342. count++;
  343. invert = 100 - count;
  344. tempr = (((Primary[0] * count) + (Secondary[0] * invert)) / 100);
  345. tempb = (((Primary[2] * count) + (Secondary[2] * invert)) / 100);
  346. tempg = (((Primary[1] * count) + (Secondary[1] * invert)) / 100);
  347. }
  348. else {
  349. Rising = false;
  350. }
  351. }
  352. if (Rising = false) {
  353. if ( count > 0 ) {
  354. count--;
  355. invert = 100 - count;
  356. tempr = (((Primary[0] * count) + (Secondary[0] * invert)) / 100);
  357. tempb = (((Primary[2] * count) + (Secondary[2] * invert)) / 100);
  358. tempg = (((Primary[1] * count) + (Secondary[1] * invert)) / 100);
  359. }
  360. else {
  361. Rising = true;
  362. }
  363. }
  364. out = buttoncheck();
  365. r = int(tempr);
  366. b = int(tempb);
  367. g = int(tempg);
  368. GlobalSet(r, g, b);
  369. delay(20);
  370. } while (out == 0);
  371. return (out);
  372. }
  373.  
  374. void colourhop() { //shuffles the colours, completed
  375. first++;
  376. if (first == second) {
  377. first++;
  378. }
  379. if (first == 4) {
  380. first = 0;
  381. second ++;
  382. }
  383. if (second == 4) {
  384. second = 0;
  385. }
  386. if (second == first) {
  387. second++;
  388. }
  389. }
  390.  
  391. void GlobalSet(int red, int green, int blue) {
  392. for (int count = 0; count < 42; count++) {
  393. RedOut[count] = red;
  394. GreenOut[count] = green;
  395. BlueOut[count] = blue;
  396. }
  397. DisplayArrays();
  398. return;
  399. }
  400.  
  401. int buttoncheck() { //returns a value between 0-7 (3 binary) completed
  402. int out = 0;
  403.  
  404. if (digitalRead(button1) == HIGH) {
  405. out = out + 1;
  406. }
  407. if (digitalRead(button2) == HIGH) {
  408. out = out + 2;
  409. }
  410. if (digitalRead(button3) == HIGH) {
  411. out = out + 4;
  412. }
  413. if (digitalRead(button4) == HIGH) { //button 4 is like a sleep button
  414. GlobalSet(0 , 0 , 0);
  415. out = 10;
  416. while (digitalRead(button2 == LOW)){
  417. delay(400);
  418. }
  419. }
  420. return (out);
  421. }
  422.  
  423. void Tlcdo(int addr, int powr) { //roughly changes range from 0-255 to 0-4095, exact numbers don't matter much
  424. int temp = powr * 16;
  425. Tlc.set(addr, temp);
  426. return;
  427. }
  428.  
  429. void DisplayArrays() { //turns arrays into actions completed
  430. int WS = 0; //number for the LED position, the LED is called a WS2812B.
  431. for (int count = 8; count < 42; count++) {
  432. if (count == 18) {
  433. count = count + 4; //lumps the 30 LED's together, and this lets me skip over the fan in the back
  434. }
  435. leds[WS].r = RedOut[count];
  436. leds[WS].g = GreenOut[count];
  437. leds[WS].b = BlueOut[count];
  438. WS++;
  439. }
  440. FastLED.show();
  441. Tlcdo(1, BlueOut[0]);
  442. Tlcdo(2, GreenOut[0]);
  443. Tlcdo(3, RedOut[0]);
  444. Tlcdo(4, BlueOut[1]);
  445. Tlcdo(5, GreenOut[1]);
  446. Tlcdo(6, RedOut[1]);
  447. Tlcdo(7, BlueOut[2]);
  448. Tlcdo(8, GreenOut[2]);
  449. Tlcdo(9, RedOut[2]);
  450. Tlcdo(10, BlueOut[3]);
  451. Tlcdo(11, GreenOut[3]);
  452. Tlcdo(12, RedOut[3]);
  453.  
  454. Tlcdo(17, BlueOut[4]);
  455. Tlcdo(18, GreenOut[4]);
  456. Tlcdo(19, RedOut[4]);
  457. Tlcdo(20, BlueOut[5]);
  458. Tlcdo(21, GreenOut[5]);
  459. Tlcdo(22, RedOut[5]);
  460. Tlcdo(23, BlueOut[6]);
  461. Tlcdo(24, GreenOut[6]);
  462. Tlcdo(25, RedOut[6]);
  463. Tlcdo(26, BlueOut[7]);
  464. Tlcdo(27, GreenOut[7]);
  465. Tlcdo(28, RedOut[7]);
  466.  
  467. Tlcdo(33, BlueOut[18]);
  468. Tlcdo(34, GreenOut[18]);
  469. Tlcdo(35, RedOut[18]);
  470. Tlcdo(36, BlueOut[19]);
  471. Tlcdo(37, GreenOut[19]);
  472. Tlcdo(38, RedOut[19]);
  473. Tlcdo(39, BlueOut[20]);
  474. Tlcdo(40, GreenOut[20]);
  475. Tlcdo(41, RedOut[20]);
  476. Tlcdo(42, BlueOut[21]);
  477. Tlcdo(43, GreenOut[21]);
  478. Tlcdo(44, RedOut[21]);
  479. Tlc.update();
  480. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement