Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 3.g
- 3b/2
- Pozdravljeni!
- Zaporedje luči je 123212321...
- Ena ponovitev traja 5 sekund.
- Prehod pomeni, da svetita obe luči (1. Luč se ugaša, 2. Luč se prižiga)
- 1. luč = 1 sekunda
- Prehod 1.-2. luč = 0.5 sekunde
- 2. luč = 1 sekunda
- Prehod 2.-3. luč = 0.5 sekunde
- 3. luč = 1 sekunda
- Prehod 3.-2. luč = 0.5 sekunde
- Prehod 2.-1. luč = 0.5 sekunde
- In potem se ponovi.
- (1,prehod,2,prehod,3,prehod,prehod,1,prehod,2...)
- 3b/1
- Luč 1 sama sveti 1 sekundo
- prehod iz 1-2 je pol sekunde
- luč 2 sama sveti 1 sekundo
- prehod 2-3 je pol sekunde
- luč 3 sama sveti 1 sekundo
- prehod 3-1 pol sekunde.
- */
- const int LED1 = 3; // the pin for the LED
- const int LED2 = 5; // the pin for the LED
- const int LED3 = 6; // the pin for the LED
- const int LED4 = 9; // the pin for the LED
- const int LED5 = 10; // the pin for the LED
- const int LED6 = 11; // the pin for the LED
- int i = 0; // We'll use this to count up and down
- int j = 0; // We'll use this to count up and down
- int k = 0; // We'll use this to count up and down
- int l = 0; // We'll use this to count up and down
- int m = 0; // We'll use this to count up and down
- int n = 0; // We'll use this to count up and down
- unsigned long currentMillis;
- unsigned long LED1StartMillis;
- unsigned long LED2StartMillis;
- unsigned long LED3StartMillis;
- unsigned long LED4StartMillis;
- unsigned long LED5StartMillis;
- unsigned long LED6StartMillis;
- unsigned long fade1StartMillis;
- unsigned long fade2StartMillis;
- unsigned long fade3StartMillis;
- unsigned long fade4StartMillis;
- unsigned long fade5StartMillis;
- unsigned long fade6StartMillis;
- const unsigned long LED1fadeUpPeriod = 0;
- const unsigned long LED1upPeriod = 400;
- const unsigned long LED1fadeDownPeriod = 410;
- const unsigned long LED1downPeriod = 1800;
- const unsigned long LED2fadeUpPeriod = 0;
- const unsigned long LED2upPeriod = 400;
- const unsigned long LED2fadeDownPeriod = 410;
- const unsigned long LED2downPeriod = 1800;
- const unsigned long LED3fadeUpPeriod = 0;
- const unsigned long LED3upPeriod = 400;
- const unsigned long LED3fadeDownPeriod = 410;
- const unsigned long LED3downPeriod = 1800;
- const unsigned long LED4fadeUpPeriod = 0;
- const unsigned long LED4upPeriod = 400;
- const unsigned long LED4fadeDownPeriod = 410;
- const unsigned long LED4downPeriod = 1800;
- const unsigned long LED5fadeUpPeriod = 0;
- const unsigned long LED5upPeriod = 400;
- const unsigned long LED5fadeDownPeriod = 410;
- const unsigned long LED5downPeriod = 1800;
- const unsigned long LED6fadeUpPeriod = 0;
- const unsigned long LED6upPeriod = 400;
- const unsigned long LED6fadeDownPeriod = 410;
- const unsigned long LED6downPeriod = 1800;
- /////
- const unsigned long fade1Period = 5;
- const unsigned long fade2Period = 5;
- const unsigned long fade3Period = 5;
- const unsigned long fade4Period = 5;
- const unsigned long fade5Period = 5;
- const unsigned long fade6Period = 5;
- int brightness1 = 0; //initial brightness of LED
- int increment1 = 8; //amount to change PWM value at each change
- int brightness2 = 0; //initial brightness of LED
- int increment2 = 8; //amount to change PWM value at each change
- int brightness3 = 0; //initial brightness of LED
- int increment3 = 8; //amount to change PWM value at each change
- int brightness4 = 0; //initial brightness of LED
- int increment4 = 8; //amount to change PWM value at each change
- int brightness5 = 0; //initial brightness of LED
- int increment5 = 8; //amount to change PWM value at each change
- int brightness6 = 0; //initial brightness of LED
- int increment6 = 8; //amount to change PWM value at each change
- int state1 = 0;
- int state2 = 0;
- int state3 = 0;
- int state4 = 0;
- int state5 = 0;
- int state6 = 0;
- void setup() {
- Serial.begin(9600);
- pinMode(LED1, OUTPUT); // tell Arduino LED is an output
- pinMode(LED2, OUTPUT); // tell Arduino LED is an output
- pinMode(LED3, OUTPUT); // tell Arduino LED is an output
- pinMode(LED4, OUTPUT); // tell Arduino LED is an output
- pinMode(LED5, OUTPUT); // tell Arduino LED is an output
- pinMode(LED6, OUTPUT); // tell Arduino LED is an output
- LED1StartMillis = millis()-300;
- LED2StartMillis = millis()-600;
- LED3StartMillis = millis()-900;
- LED4StartMillis = millis()-1200;
- LED5StartMillis = millis()-1500;
- LED6StartMillis = millis()-1800;
- }
- void loop() {
- currentMillis = millis();
- Serial.println(LED1StartMillis);
- Serial.println(currentMillis);
- // Serial.println(LED1StartMillis);
- if ((currentMillis - LED1StartMillis >= LED1fadeUpPeriod) && (currentMillis - LED1StartMillis < LED1upPeriod )) {
- state1 = 1;
- // Serial.println(fadeUpp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED1StartMillis >= LED1upPeriod) && (currentMillis - LED1StartMillis < LED1fadeDownPeriod)) {
- state1 = 2;
- // Serial.println(Upp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED1StartMillis >= LED1fadeDownPeriod) && (currentMillis - LED1StartMillis < LED1downPeriod)) {
- state1 = 3;
- // Serial.println(fadeDownn);
- // LED1StartMillis = currentMillis;
- }
- if (currentMillis - LED1StartMillis >= LED1downPeriod) {
- state1 = 4;
- // Serial.println(Downn);
- // LED1StartMillis = currentMillis;
- }
- if (state1 == 1) {
- if (currentMillis - fade1StartMillis >= fade1Period) {
- analogWrite(LED1, brightness1);
- brightness1 = brightness1 + increment1; //will wrap round because brightness is an unsigned data type
- fade1StartMillis = currentMillis;
- }
- if (brightness1 >= 222) {
- brightness1 = 222;
- }
- }
- if (state1 == 2) {
- analogWrite(LED1, 222);
- }
- if (state1 == 3) {
- if (currentMillis - fade1StartMillis >= fade1Period) {
- analogWrite(LED1, brightness1);
- brightness1 = brightness1 - increment1; //will wrap round because brightness is an unsigned data type
- fade1StartMillis = currentMillis;
- }
- if (brightness1 <= 0) {
- brightness1 = 0;
- }
- }
- if (state1 == 4) {
- analogWrite(LED1, 0);
- LED1StartMillis = currentMillis;
- state1 = 0;
- }
- /////////////////////////////////////////////////////
- if ((currentMillis - LED2StartMillis >= LED2fadeUpPeriod) && (currentMillis - LED2StartMillis < LED2upPeriod )) {
- state2 = 1;
- // Serial.println(fadeUpp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED2StartMillis >= LED2upPeriod) && (currentMillis - LED2StartMillis < LED2fadeDownPeriod)) {
- state2 = 2;
- // Serial.println(Upp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED2StartMillis >= LED2fadeDownPeriod) && (currentMillis - LED2StartMillis < LED2downPeriod)) {
- state2 = 3;
- // Serial.println(fadeDownn);
- // LED1StartMillis = currentMillis;
- }
- if (currentMillis - LED2StartMillis >= LED2downPeriod) {
- state2 = 4;
- // Serial.println(Downn);
- // LED1StartMillis = currentMillis;
- }
- if (state2 == 1) {
- if (currentMillis - fade2StartMillis >= fade2Period) {
- analogWrite(LED2, brightness2);
- brightness2 = brightness2 + increment2; //will wrap round because brightness is an unsigned data type
- fade2StartMillis = currentMillis;
- }
- if (brightness2 >= 222) {
- brightness2 = 222;
- }
- }
- if (state2 == 2) {
- analogWrite(LED2, 222);
- }
- if (state2 == 3) {
- if (currentMillis - fade2StartMillis >= fade2Period) {
- analogWrite(LED2, brightness2);
- brightness2 = brightness2 - increment2; //will wrap round because brightness is an unsigned data type
- fade2StartMillis = currentMillis;
- }
- if (brightness2 <= 0) {
- brightness2 = 0;
- }
- }
- if (state2 == 4) {
- analogWrite(LED2, 0);
- LED2StartMillis = currentMillis;
- state2 = 0;
- }
- ///////////////////////////////////////////////////////
- if ((currentMillis - LED3StartMillis >= LED3fadeUpPeriod) && (currentMillis - LED3StartMillis < LED3upPeriod )) {
- state3 = 1;
- // Serial.println(fadeUpp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED3StartMillis >= LED3upPeriod) && (currentMillis - LED3StartMillis < LED3fadeDownPeriod)) {
- state3 = 2;
- // Serial.println(Upp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED3StartMillis >= LED3fadeDownPeriod) && (currentMillis - LED3StartMillis < LED3downPeriod)) {
- state3 = 3;
- // Serial.println(fadeDownn);
- // LED1StartMillis = currentMillis;
- }
- if (currentMillis - LED3StartMillis >= LED3downPeriod) {
- state3 = 4;
- // Serial.println(Downn);
- // LED1StartMillis = currentMillis;
- }
- if (state3 == 1) {
- if (currentMillis - fade3StartMillis >= fade3Period) {
- analogWrite(LED3, brightness3);
- brightness3 = brightness3 + increment3; //will wrap round because brightness is an unsigned data type
- fade3StartMillis = currentMillis;
- }
- if (brightness3 >= 222) {
- brightness3 = 222;
- }
- }
- if (state3 == 2) {
- analogWrite(LED3, 222);
- }
- if (state3 == 3) {
- if (currentMillis - fade3StartMillis >= fade3Period) {
- analogWrite(LED3, brightness3);
- brightness3 = brightness3 - increment3; //will wrap round because brightness is an unsigned data type
- fade3StartMillis = currentMillis;
- }
- if (brightness3 <= 0) {
- brightness3 = 0;
- }
- }
- if (state3 == 4) {
- analogWrite(LED3, 0);
- LED3StartMillis = currentMillis;
- state3 = 0;
- }
- ///////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////
- if ((currentMillis - LED4StartMillis >= LED4fadeUpPeriod) && (currentMillis - LED4StartMillis < LED4upPeriod )) {
- state4 = 1;
- // Serial.println(fadeUpp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED4StartMillis >= LED4upPeriod) && (currentMillis - LED4StartMillis < LED4fadeDownPeriod)) {
- state4 = 2;
- // Serial.println(Upp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED4StartMillis >= LED4fadeDownPeriod) && (currentMillis - LED4StartMillis < LED4downPeriod)) {
- state4 = 3;
- // Serial.println(fadeDownn);
- // LED1StartMillis = currentMillis;
- }
- if (currentMillis - LED4StartMillis >= LED4downPeriod) {
- state4 = 4;
- // Serial.println(Downn);
- // LED1StartMillis = currentMillis;
- }
- if (state4 == 1) {
- if (currentMillis - fade4StartMillis >= fade4Period) {
- analogWrite(LED4, brightness4);
- brightness4 = brightness4 + increment4; //will wrap round because brightness is an unsigned data type
- fade4StartMillis = currentMillis;
- }
- if (brightness4 >= 222) {
- brightness4 = 222;
- }
- }
- if (state4 == 2) {
- analogWrite(LED4, 222);
- }
- if (state4 == 3) {
- if (currentMillis - fade4StartMillis >= fade4Period) {
- analogWrite(LED4, brightness4);
- brightness4 = brightness4 - increment4; //will wrap round because brightness is an unsigned data type
- fade4StartMillis = currentMillis;
- }
- if (brightness4 <= 0) {
- brightness4 = 0;
- }
- }
- if (state4 == 4) {
- analogWrite(LED4, 0);
- LED4StartMillis = currentMillis;
- state4 = 0;
- }
- /////////////////////////////////////////////////////
- if ((currentMillis - LED5StartMillis >= LED5fadeUpPeriod) && (currentMillis - LED5StartMillis < LED5upPeriod )) {
- state5 = 1;
- // Serial.println(fadeUpp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED5StartMillis >= LED5upPeriod) && (currentMillis - LED5StartMillis < LED5fadeDownPeriod)) {
- state5 = 2;
- // Serial.println(Upp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED5StartMillis >= LED5fadeDownPeriod) && (currentMillis - LED5StartMillis < LED5downPeriod)) {
- state5 = 3;
- // Serial.println(fadeDownn);
- // LED1StartMillis = currentMillis;
- }
- if (currentMillis - LED5StartMillis >= LED5downPeriod) {
- state5 = 4;
- // Serial.println(Downn);
- // LED1StartMillis = currentMillis;
- }
- if (state5 == 1) {
- if (currentMillis - fade5StartMillis >= fade5Period) {
- analogWrite(LED5, brightness5);
- brightness5 = brightness5 + increment5; //will wrap round because brightness is an unsigned data type
- fade5StartMillis = currentMillis;
- }
- if (brightness5 >= 222) {
- brightness5 = 222;
- }
- }
- if (state5 == 2) {
- analogWrite(LED5, 222);
- }
- if (state5 == 3) {
- if (currentMillis - fade5StartMillis >= fade5Period) {
- analogWrite(LED5, brightness5);
- brightness5 = brightness5 - increment5; //will wrap round because brightness is an unsigned data type
- fade5StartMillis = currentMillis;
- }
- if (brightness5 <= 0) {
- brightness5 = 0;
- }
- }
- if (state5 == 4) {
- analogWrite(LED5, 0);
- LED5StartMillis = currentMillis;
- state5 = 0;
- }
- ///////////////////////////////////////////////////////
- if ((currentMillis - LED6StartMillis >= LED6fadeUpPeriod) && (currentMillis - LED6StartMillis < LED6upPeriod )) {
- state6 = 1;
- // Serial.println(fadeUpp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED6StartMillis >= LED6upPeriod) && (currentMillis - LED6StartMillis < LED6fadeDownPeriod)) {
- state6 = 2;
- // Serial.println(Upp);
- // LED1StartMillis = currentMillis;
- }
- if ((currentMillis - LED6StartMillis >= LED6fadeDownPeriod) && (currentMillis - LED6StartMillis < LED6downPeriod)) {
- state6 = 3;
- // Serial.println(fadeDownn);
- // LED1StartMillis = currentMillis;
- }
- if (currentMillis - LED6StartMillis >= LED6downPeriod) {
- state6 = 4;
- // Serial.println(Downn);
- // LED1StartMillis = currentMillis;
- }
- if (state6 == 1) {
- if (currentMillis - fade6StartMillis >= fade6Period) {
- analogWrite(LED6, brightness6);
- brightness6 = brightness6 + increment6; //will wrap round because brightness is an unsigned data type
- fade6StartMillis = currentMillis;
- }
- if (brightness6 >= 222) {
- brightness6 = 222;
- }
- }
- if (state6 == 2) {
- analogWrite(LED6, 222);
- }
- if (state6 == 3) {
- if (currentMillis - fade6StartMillis >= fade6Period) {
- analogWrite(LED6, brightness6);
- brightness6 = brightness6 - increment6; //will wrap round because brightness is an unsigned data type
- fade6StartMillis = currentMillis;
- }
- if (brightness6 <= 0) {
- brightness6 = 0;
- }
- }
- if (state6 == 4) {
- analogWrite(LED6, 0);
- LED6StartMillis = currentMillis;
- state6 = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment