Wednesday, October 8, 2014

Arduino PWM





int ledPin = 11;    // LED connected to digital pin 9

void setup()  { 
  // nothing happens in setup 

void loop()  { 
  
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 1 ; fadeValue <= 98; fadeValue +=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(5);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 150 ; fadeValue >= 1; fadeValue -=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(5);                            
  }
  
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 25 ; fadeValue <= 70; fadeValue +=20) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 250 ; fadeValue >= 15; fadeValue -=20) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(50);    
    
  }
      
 }          

Felipe Martinez, Sergio Roman, Sara Toro, Karen Angulo

No comments:

Post a Comment