30.12.12

Näide Daniili programmist

Õ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);
}

Kuuse kontrollimise programm

Kuna puudujatel on mõningaid raskusi kuuse töö kontrollimisega siis panen siia jupi programmi mis vilgutab lede pin-idel 3,5,6,9,10 ja 11. Tähtis on Ledid õigesti ühendada.

void setup(){
  pinMode(3,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
}
void loop(){
digitalWrite(3, HIGH);
  delay(6000);
  digitalWrite(3, LOW);
digitalWrite(5, HIGH);
  delay(5000);
  digitalWrite(5, LOW);
digitalWrite(6, HIGH);
  delay(4000);
  digitalWrite(6, LOW);
digitalWrite(9, HIGH);
  delay(3000);
  digitalWrite(9, LOW);
digitalWrite(10, HIGH);
  delay(2000);
  digitalWrite(10, LOW);
digitalWrite(11, HIGH);
  delay(1000);
  digitalWrite(11, LOW);
}

27.12.12

Tunnid aastavahetusel

Ilusat pühadeaega ja aastavahetust Teile! Olen Kullos neljapäeval 27.detsembril kella 18.00-st. Järgmine tund aga oleks juba uuel aastal 3.jaanuaril ja ikka algusega 18.00.
Parimate soovidega õpetaja Mait!

2.12.12

Esmaspäevane tund

Esmaspäeval kell 18.00 saab nokitseda oma projekte ja lõpetada pooleli olevaid töid.