Õpetaja töö kõrvale võrdludeks veel üks vilgutaja programm Daniil Lepkinilt.
// int b1_6=8;
// int b2_5=9;
// int b3_4=10;
// int y1_6=7;
// int y2_5=6; //* - to change
// int y3_4=5;
// int r1_6=2;
// int r2_5=3;
// int r3_4=4;
// int g1_6=11;
// int g2_5=12;
// int g3_4=13;
#define LED_AMOUNT 12 //*PWM ports amount
int r;
int pause = 0;
int state[LED_AMOUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int counter[LED_AMOUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int pwm_state[LED_AMOUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int time_pwm_up[LED_AMOUNT] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int time_pwm_down[LED_AMOUNT] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int time_on[LED_AMOUNT] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int time_off[LED_AMOUNT] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int led_ports[LED_AMOUNT] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; //*Ports you used for leds
void setup()
{
for(int i = 2; i <= (LED_AMOUNT + 1); i++)
{
pinMode(i, OUTPUT);
digitalWrite(i,LOW);
}
}
void loop()
{
if (pause == 0)
{
for(int u = 0; u <= 2; u++)
{
r = int(random(0,LED_AMOUNT)); // For chosing a random LED group
if(state[r] == 0) // and it's time parameters
{
state[r] = 1;
time_pwm_up[r] = int((random(2, 5))*5);
counter[r] = time_pwm_up[r];
pwm_state[r] = 0;
time_pwm_down[r] = int((random(2, 5))*5);
time_on[r] = int((random(20, 40))*5);
time_off[r] = int((random(20, 50))*10);
u = 3;
pause = int((random(50, 100))*10);
}
}
}
else pause--;
for(int i = 0; i <= (LED_AMOUNT - 1); i++) //LED group listing
{
switch(state[i])
{
case 0: //LED group waiting for beginning it's work
break;
case 1: //LED group starting it's PWM growth
if(counter[i]==0)
{
counter[i] = time_pwm_up[i];
(pwm_state[i])++;
if(pwm_state[i] == 255)
{
state[i] = 2;
counter[i] = time_on[i];
}
}
else (counter[i])--;
break;
case 2: //Keeping LED group on
if(counter[i] == 0)
{
counter[i] = time_pwm_down[i];
state[i] = 3;
}
else
{
(counter[i])--;
}
break;
case 3: //LED group starting it's PWM fade
if(counter[i] == 0)
{
counter[i] = time_pwm_down[i];
(pwm_state[i])--;
if(pwm_state[i] == 0)
{
state[i] = 4;
counter[i] = time_off[i];
}
}
else (counter[i])--;
break;
case 4: //Keeping LED group off
if(counter[i] == 0)
state[i] = 0;
else
(counter[i])--;
break;
default:
state[i] = 0;
}
analogWrite(led_ports[i], pwm_state[i]); //writing group's PWM state
}
delay(1);
}
Kommentaare ei ole:
Postita kommentaar