Guest User

Untitled

a guest
Nov 22nd, 2022
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.79 KB | Software | 0 0
  1. /*
  2.  
  3. 3.g
  4.  
  5. 3b/2
  6.  
  7. Pozdravljeni!
  8. Zaporedje luči je 123212321...
  9. Ena ponovitev traja 5 sekund.
  10. Prehod pomeni, da svetita obe luči (1. Luč se ugaša, 2. Luč se prižiga)
  11.  
  12. 1. luč = 1 sekunda
  13. Prehod 1.-2. luč = 0.5 sekunde
  14. 2. luč = 1 sekunda
  15. Prehod 2.-3. luč = 0.5 sekunde
  16. 3. luč = 1 sekunda
  17. Prehod 3.-2. luč = 0.5 sekunde
  18. Prehod 2.-1. luč = 0.5 sekunde
  19.  
  20. In potem se ponovi.
  21. (1,prehod,2,prehod,3,prehod,prehod,1,prehod,2...)
  22.  
  23.  
  24.  
  25. 3b/1
  26. Luč 1 sama sveti 1 sekundo
  27. prehod iz 1-2 je pol sekunde
  28. luč 2 sama sveti 1 sekundo
  29. prehod 2-3 je pol sekunde
  30. luč 3 sama sveti 1 sekundo
  31. prehod 3-1 pol sekunde.
  32. */
  33.  
  34. const int LED1 = 3; // the pin for the LED
  35. const int LED2 = 5; // the pin for the LED
  36. const int LED3 = 6; // the pin for the LED
  37.  
  38. const int LED4 = 9; // the pin for the LED
  39. const int LED5 = 10; // the pin for the LED
  40. const int LED6 = 11; // the pin for the LED
  41.  
  42. int i = 0; // We'll use this to count up and down
  43. int j = 0; // We'll use this to count up and down
  44. int k = 0; // We'll use this to count up and down
  45.  
  46. int l = 0; // We'll use this to count up and down
  47. int m = 0; // We'll use this to count up and down
  48. int n = 0; // We'll use this to count up and down
  49.  
  50. unsigned long currentMillis;
  51.  
  52. unsigned long LED1StartMillis;
  53. unsigned long LED2StartMillis;
  54. unsigned long LED3StartMillis;
  55.  
  56. unsigned long LED4StartMillis;
  57. unsigned long LED5StartMillis;
  58. unsigned long LED6StartMillis;
  59.  
  60. unsigned long fade1StartMillis;
  61. unsigned long fade2StartMillis;
  62. unsigned long fade3StartMillis;
  63.  
  64. unsigned long fade4StartMillis;
  65. unsigned long fade5StartMillis;
  66. unsigned long fade6StartMillis;
  67.  
  68.  
  69. const unsigned long LED1fadeUpPeriod = 0;
  70. const unsigned long LED1upPeriod = 400;
  71. const unsigned long LED1fadeDownPeriod = 410;
  72. const unsigned long LED1downPeriod = 1800;
  73.  
  74. const unsigned long LED2fadeUpPeriod = 0;
  75. const unsigned long LED2upPeriod = 400;
  76. const unsigned long LED2fadeDownPeriod = 410;
  77. const unsigned long LED2downPeriod = 1800;
  78.  
  79. const unsigned long LED3fadeUpPeriod = 0;
  80. const unsigned long LED3upPeriod = 400;
  81. const unsigned long LED3fadeDownPeriod = 410;
  82. const unsigned long LED3downPeriod = 1800;
  83.  
  84. const unsigned long LED4fadeUpPeriod = 0;
  85. const unsigned long LED4upPeriod = 400;
  86. const unsigned long LED4fadeDownPeriod = 410;
  87. const unsigned long LED4downPeriod = 1800;
  88.  
  89. const unsigned long LED5fadeUpPeriod = 0;
  90. const unsigned long LED5upPeriod = 400;
  91. const unsigned long LED5fadeDownPeriod = 410;
  92. const unsigned long LED5downPeriod = 1800;
  93.  
  94. const unsigned long LED6fadeUpPeriod = 0;
  95. const unsigned long LED6upPeriod = 400;
  96. const unsigned long LED6fadeDownPeriod = 410;
  97. const unsigned long LED6downPeriod = 1800;
  98.  
  99. /////
  100.  
  101. const unsigned long fade1Period = 5;
  102. const unsigned long fade2Period = 5;
  103. const unsigned long fade3Period = 5;
  104.  
  105. const unsigned long fade4Period = 5;
  106. const unsigned long fade5Period = 5;
  107. const unsigned long fade6Period = 5;
  108.  
  109.  
  110.  
  111.  
  112.  
  113. int brightness1 = 0; //initial brightness of LED
  114. int increment1 = 8; //amount to change PWM value at each change
  115.  
  116. int brightness2 = 0; //initial brightness of LED
  117. int increment2 = 8; //amount to change PWM value at each change
  118.  
  119. int brightness3 = 0; //initial brightness of LED
  120. int increment3 = 8; //amount to change PWM value at each change
  121.  
  122. int brightness4 = 0; //initial brightness of LED
  123. int increment4 = 8; //amount to change PWM value at each change
  124.  
  125. int brightness5 = 0; //initial brightness of LED
  126. int increment5 = 8; //amount to change PWM value at each change
  127.  
  128. int brightness6 = 0; //initial brightness of LED
  129. int increment6 = 8; //amount to change PWM value at each change
  130.  
  131. int state1 = 0;
  132. int state2 = 0;
  133. int state3 = 0;
  134.  
  135. int state4 = 0;
  136. int state5 = 0;
  137. int state6 = 0;
  138.  
  139.  
  140.  
  141. void setup() {
  142. Serial.begin(9600);
  143. pinMode(LED1, OUTPUT); // tell Arduino LED is an output
  144. pinMode(LED2, OUTPUT); // tell Arduino LED is an output
  145. pinMode(LED3, OUTPUT); // tell Arduino LED is an output
  146.  
  147. pinMode(LED4, OUTPUT); // tell Arduino LED is an output
  148. pinMode(LED5, OUTPUT); // tell Arduino LED is an output
  149. pinMode(LED6, OUTPUT); // tell Arduino LED is an output
  150.  
  151. LED1StartMillis = millis()-300;
  152. LED2StartMillis = millis()-600;
  153. LED3StartMillis = millis()-900;
  154.  
  155. LED4StartMillis = millis()-1200;
  156. LED5StartMillis = millis()-1500;
  157. LED6StartMillis = millis()-1800;
  158. }
  159.  
  160. void loop() {
  161. currentMillis = millis();
  162. Serial.println(LED1StartMillis);
  163. Serial.println(currentMillis);
  164. // Serial.println(LED1StartMillis);
  165.  
  166. if ((currentMillis - LED1StartMillis >= LED1fadeUpPeriod) && (currentMillis - LED1StartMillis < LED1upPeriod )) {
  167. state1 = 1;
  168. // Serial.println(fadeUpp);
  169. // LED1StartMillis = currentMillis;
  170. }
  171.  
  172. if ((currentMillis - LED1StartMillis >= LED1upPeriod) && (currentMillis - LED1StartMillis < LED1fadeDownPeriod)) {
  173. state1 = 2;
  174. // Serial.println(Upp);
  175. // LED1StartMillis = currentMillis;
  176. }
  177.  
  178. if ((currentMillis - LED1StartMillis >= LED1fadeDownPeriod) && (currentMillis - LED1StartMillis < LED1downPeriod)) {
  179. state1 = 3;
  180. // Serial.println(fadeDownn);
  181. // LED1StartMillis = currentMillis;
  182. }
  183.  
  184. if (currentMillis - LED1StartMillis >= LED1downPeriod) {
  185. state1 = 4;
  186. // Serial.println(Downn);
  187. // LED1StartMillis = currentMillis;
  188. }
  189.  
  190. if (state1 == 1) {
  191. if (currentMillis - fade1StartMillis >= fade1Period) {
  192. analogWrite(LED1, brightness1);
  193. brightness1 = brightness1 + increment1; //will wrap round because brightness is an unsigned data type
  194. fade1StartMillis = currentMillis;
  195. }
  196. if (brightness1 >= 222) {
  197. brightness1 = 222;
  198. }
  199. }
  200.  
  201. if (state1 == 2) {
  202. analogWrite(LED1, 222);
  203. }
  204.  
  205. if (state1 == 3) {
  206. if (currentMillis - fade1StartMillis >= fade1Period) {
  207. analogWrite(LED1, brightness1);
  208. brightness1 = brightness1 - increment1; //will wrap round because brightness is an unsigned data type
  209. fade1StartMillis = currentMillis;
  210. }
  211. if (brightness1 <= 0) {
  212. brightness1 = 0;
  213. }
  214. }
  215.  
  216. if (state1 == 4) {
  217. analogWrite(LED1, 0);
  218. LED1StartMillis = currentMillis;
  219. state1 = 0;
  220. }
  221.  
  222. /////////////////////////////////////////////////////
  223.  
  224. if ((currentMillis - LED2StartMillis >= LED2fadeUpPeriod) && (currentMillis - LED2StartMillis < LED2upPeriod )) {
  225. state2 = 1;
  226. // Serial.println(fadeUpp);
  227. // LED1StartMillis = currentMillis;
  228. }
  229.  
  230. if ((currentMillis - LED2StartMillis >= LED2upPeriod) && (currentMillis - LED2StartMillis < LED2fadeDownPeriod)) {
  231. state2 = 2;
  232. // Serial.println(Upp);
  233. // LED1StartMillis = currentMillis;
  234. }
  235.  
  236. if ((currentMillis - LED2StartMillis >= LED2fadeDownPeriod) && (currentMillis - LED2StartMillis < LED2downPeriod)) {
  237. state2 = 3;
  238. // Serial.println(fadeDownn);
  239. // LED1StartMillis = currentMillis;
  240. }
  241.  
  242. if (currentMillis - LED2StartMillis >= LED2downPeriod) {
  243. state2 = 4;
  244. // Serial.println(Downn);
  245. // LED1StartMillis = currentMillis;
  246. }
  247.  
  248. if (state2 == 1) {
  249. if (currentMillis - fade2StartMillis >= fade2Period) {
  250. analogWrite(LED2, brightness2);
  251. brightness2 = brightness2 + increment2; //will wrap round because brightness is an unsigned data type
  252. fade2StartMillis = currentMillis;
  253. }
  254. if (brightness2 >= 222) {
  255. brightness2 = 222;
  256. }
  257. }
  258.  
  259. if (state2 == 2) {
  260. analogWrite(LED2, 222);
  261. }
  262.  
  263. if (state2 == 3) {
  264. if (currentMillis - fade2StartMillis >= fade2Period) {
  265. analogWrite(LED2, brightness2);
  266. brightness2 = brightness2 - increment2; //will wrap round because brightness is an unsigned data type
  267. fade2StartMillis = currentMillis;
  268. }
  269. if (brightness2 <= 0) {
  270. brightness2 = 0;
  271. }
  272. }
  273.  
  274. if (state2 == 4) {
  275. analogWrite(LED2, 0);
  276. LED2StartMillis = currentMillis;
  277. state2 = 0;
  278. }
  279.  
  280. ///////////////////////////////////////////////////////
  281.  
  282. if ((currentMillis - LED3StartMillis >= LED3fadeUpPeriod) && (currentMillis - LED3StartMillis < LED3upPeriod )) {
  283. state3 = 1;
  284. // Serial.println(fadeUpp);
  285. // LED1StartMillis = currentMillis;
  286. }
  287.  
  288. if ((currentMillis - LED3StartMillis >= LED3upPeriod) && (currentMillis - LED3StartMillis < LED3fadeDownPeriod)) {
  289. state3 = 2;
  290. // Serial.println(Upp);
  291. // LED1StartMillis = currentMillis;
  292. }
  293.  
  294. if ((currentMillis - LED3StartMillis >= LED3fadeDownPeriod) && (currentMillis - LED3StartMillis < LED3downPeriod)) {
  295. state3 = 3;
  296. // Serial.println(fadeDownn);
  297. // LED1StartMillis = currentMillis;
  298. }
  299.  
  300. if (currentMillis - LED3StartMillis >= LED3downPeriod) {
  301. state3 = 4;
  302. // Serial.println(Downn);
  303. // LED1StartMillis = currentMillis;
  304. }
  305.  
  306. if (state3 == 1) {
  307. if (currentMillis - fade3StartMillis >= fade3Period) {
  308. analogWrite(LED3, brightness3);
  309. brightness3 = brightness3 + increment3; //will wrap round because brightness is an unsigned data type
  310. fade3StartMillis = currentMillis;
  311. }
  312. if (brightness3 >= 222) {
  313. brightness3 = 222;
  314. }
  315. }
  316.  
  317. if (state3 == 2) {
  318. analogWrite(LED3, 222);
  319. }
  320.  
  321. if (state3 == 3) {
  322. if (currentMillis - fade3StartMillis >= fade3Period) {
  323. analogWrite(LED3, brightness3);
  324. brightness3 = brightness3 - increment3; //will wrap round because brightness is an unsigned data type
  325. fade3StartMillis = currentMillis;
  326. }
  327. if (brightness3 <= 0) {
  328. brightness3 = 0;
  329. }
  330. }
  331.  
  332. if (state3 == 4) {
  333. analogWrite(LED3, 0);
  334. LED3StartMillis = currentMillis;
  335. state3 = 0;
  336. }
  337.  
  338.  
  339. ///////////////////////////////////////////////////////
  340.  
  341. ///////////////////////////////////////////////////////
  342.  
  343. if ((currentMillis - LED4StartMillis >= LED4fadeUpPeriod) && (currentMillis - LED4StartMillis < LED4upPeriod )) {
  344. state4 = 1;
  345. // Serial.println(fadeUpp);
  346. // LED1StartMillis = currentMillis;
  347. }
  348.  
  349. if ((currentMillis - LED4StartMillis >= LED4upPeriod) && (currentMillis - LED4StartMillis < LED4fadeDownPeriod)) {
  350. state4 = 2;
  351. // Serial.println(Upp);
  352. // LED1StartMillis = currentMillis;
  353. }
  354.  
  355. if ((currentMillis - LED4StartMillis >= LED4fadeDownPeriod) && (currentMillis - LED4StartMillis < LED4downPeriod)) {
  356. state4 = 3;
  357. // Serial.println(fadeDownn);
  358. // LED1StartMillis = currentMillis;
  359. }
  360.  
  361. if (currentMillis - LED4StartMillis >= LED4downPeriod) {
  362. state4 = 4;
  363. // Serial.println(Downn);
  364. // LED1StartMillis = currentMillis;
  365. }
  366.  
  367. if (state4 == 1) {
  368. if (currentMillis - fade4StartMillis >= fade4Period) {
  369. analogWrite(LED4, brightness4);
  370. brightness4 = brightness4 + increment4; //will wrap round because brightness is an unsigned data type
  371. fade4StartMillis = currentMillis;
  372. }
  373. if (brightness4 >= 222) {
  374. brightness4 = 222;
  375. }
  376. }
  377.  
  378. if (state4 == 2) {
  379. analogWrite(LED4, 222);
  380. }
  381.  
  382. if (state4 == 3) {
  383. if (currentMillis - fade4StartMillis >= fade4Period) {
  384. analogWrite(LED4, brightness4);
  385. brightness4 = brightness4 - increment4; //will wrap round because brightness is an unsigned data type
  386. fade4StartMillis = currentMillis;
  387. }
  388. if (brightness4 <= 0) {
  389. brightness4 = 0;
  390. }
  391. }
  392.  
  393. if (state4 == 4) {
  394. analogWrite(LED4, 0);
  395. LED4StartMillis = currentMillis;
  396. state4 = 0;
  397. }
  398.  
  399. /////////////////////////////////////////////////////
  400.  
  401. if ((currentMillis - LED5StartMillis >= LED5fadeUpPeriod) && (currentMillis - LED5StartMillis < LED5upPeriod )) {
  402. state5 = 1;
  403. // Serial.println(fadeUpp);
  404. // LED1StartMillis = currentMillis;
  405. }
  406.  
  407. if ((currentMillis - LED5StartMillis >= LED5upPeriod) && (currentMillis - LED5StartMillis < LED5fadeDownPeriod)) {
  408. state5 = 2;
  409. // Serial.println(Upp);
  410. // LED1StartMillis = currentMillis;
  411. }
  412.  
  413. if ((currentMillis - LED5StartMillis >= LED5fadeDownPeriod) && (currentMillis - LED5StartMillis < LED5downPeriod)) {
  414. state5 = 3;
  415. // Serial.println(fadeDownn);
  416. // LED1StartMillis = currentMillis;
  417. }
  418.  
  419. if (currentMillis - LED5StartMillis >= LED5downPeriod) {
  420. state5 = 4;
  421. // Serial.println(Downn);
  422. // LED1StartMillis = currentMillis;
  423. }
  424.  
  425. if (state5 == 1) {
  426. if (currentMillis - fade5StartMillis >= fade5Period) {
  427. analogWrite(LED5, brightness5);
  428. brightness5 = brightness5 + increment5; //will wrap round because brightness is an unsigned data type
  429. fade5StartMillis = currentMillis;
  430. }
  431. if (brightness5 >= 222) {
  432. brightness5 = 222;
  433. }
  434. }
  435.  
  436. if (state5 == 2) {
  437. analogWrite(LED5, 222);
  438. }
  439.  
  440. if (state5 == 3) {
  441. if (currentMillis - fade5StartMillis >= fade5Period) {
  442. analogWrite(LED5, brightness5);
  443. brightness5 = brightness5 - increment5; //will wrap round because brightness is an unsigned data type
  444. fade5StartMillis = currentMillis;
  445. }
  446. if (brightness5 <= 0) {
  447. brightness5 = 0;
  448. }
  449. }
  450.  
  451. if (state5 == 4) {
  452. analogWrite(LED5, 0);
  453. LED5StartMillis = currentMillis;
  454. state5 = 0;
  455. }
  456.  
  457. ///////////////////////////////////////////////////////
  458.  
  459. if ((currentMillis - LED6StartMillis >= LED6fadeUpPeriod) && (currentMillis - LED6StartMillis < LED6upPeriod )) {
  460. state6 = 1;
  461. // Serial.println(fadeUpp);
  462. // LED1StartMillis = currentMillis;
  463. }
  464.  
  465. if ((currentMillis - LED6StartMillis >= LED6upPeriod) && (currentMillis - LED6StartMillis < LED6fadeDownPeriod)) {
  466. state6 = 2;
  467. // Serial.println(Upp);
  468. // LED1StartMillis = currentMillis;
  469. }
  470.  
  471. if ((currentMillis - LED6StartMillis >= LED6fadeDownPeriod) && (currentMillis - LED6StartMillis < LED6downPeriod)) {
  472. state6 = 3;
  473. // Serial.println(fadeDownn);
  474. // LED1StartMillis = currentMillis;
  475. }
  476.  
  477. if (currentMillis - LED6StartMillis >= LED6downPeriod) {
  478. state6 = 4;
  479. // Serial.println(Downn);
  480. // LED1StartMillis = currentMillis;
  481. }
  482.  
  483. if (state6 == 1) {
  484. if (currentMillis - fade6StartMillis >= fade6Period) {
  485. analogWrite(LED6, brightness6);
  486. brightness6 = brightness6 + increment6; //will wrap round because brightness is an unsigned data type
  487. fade6StartMillis = currentMillis;
  488. }
  489. if (brightness6 >= 222) {
  490. brightness6 = 222;
  491. }
  492. }
  493.  
  494. if (state6 == 2) {
  495. analogWrite(LED6, 222);
  496. }
  497.  
  498. if (state6 == 3) {
  499. if (currentMillis - fade6StartMillis >= fade6Period) {
  500. analogWrite(LED6, brightness6);
  501. brightness6 = brightness6 - increment6; //will wrap round because brightness is an unsigned data type
  502. fade6StartMillis = currentMillis;
  503. }
  504. if (brightness6 <= 0) {
  505. brightness6 = 0;
  506. }
  507. }
  508.  
  509. if (state6 == 4) {
  510. analogWrite(LED6, 0);
  511. LED6StartMillis = currentMillis;
  512. state6 = 0;
  513. }
  514.  
  515. }
Advertisement
Add Comment
Please, Sign In to add comment