venerdì 14 novembre 2014

Blink with delay asimmetrico.


Alla chiusura di un interruttore due led lampeggiano ciascuno con tempi propri di ON ed OFF senza l'uso dell'istruzione delay()

   
      # define BUTTON1 2
      # define BUTTON2 3
      # define LED1 6
      # define LED2 7
      
      int buttonState1 = 0;
      byte Pulse1 = 0;
      unsigned long pMillis1A = 0; 
      unsigned long Wart1A = 100;  
      unsigned long pMillis1B = 0; 
      unsigned long Wart1B = 1200; 
   
      int buttonState2 = 0;
      byte Pulse2 = 0;
      unsigned long pMillis2A = 0; 
      unsigned long Wart2A = 330;  
      unsigned long pMillis2B = 0; 
      unsigned long Wart2B = 660;      
    
    
      void setup() 
          { pinMode(BUTTON1,INPUT);
            pinMode(BUTTON2,INPUT);
            pinMode(LED1, OUTPUT);
            pinMode(LED2, OUTPUT); }
      

      void loop() {
    
      buttonState1 = digitalRead(BUTTON1);
           if ( buttonState1 == HIGH)
              { if ( millis() - pMillis1A > Wart1A)
                   { pMillis1A = millis(); 
                     Pulse1 = LOW;
                     digitalWrite(LED1, Pulse1); 
                if ( millis() - pMillis1B > Wart1B)
                    { pMillis1B = millis(); 
                      Pulse1 = HIGH;
                      digitalWrite(LED1, Pulse1);   }}}
     
      buttonState2 = digitalRead(BUTTON2);
           if ( buttonState2 == HIGH)
              { if ( millis() - pMillis2A > Wart2A)
                   { pMillis2A = millis(); 
                     Pulse2 = LOW;
                     digitalWrite(LED2, Pulse2); 
                if ( millis() - pMillis2B > Wart2B)
                    { pMillis2B = millis(); 
                      Pulse2 = HIGH;
                      digitalWrite(LED2, Pulse2);   }}}     
}

Nessun commento:

Posta un commento