Go Down

Topic: Digital PWM outputs (Read 2850 times) previous topic - next topic

dmiller5

Another question I have regards to the PWM feature. Dimming of LEDs can be achieved through different duty cycles in a PWM circuit. Specifically, I want to be able to manipulate a 2kHz frequencies duty cycle from 10% - 50% through software for different analog input values, thus allowing me to dim a string. Is there a command in the software that will allow this? I have looked around but have not run across anything that allows this inside the software. Thanks again,

Daniel

mellis

Despite its name, the analogWrite() function actually generates a digital PWM signal on pins 9, 10 or 11: http://www.arduino.cc/en/Reference/AnalogWrite

It's currently at 30 KHz, but you could change it with some 'magic' code to adjust the comparison register on the associated timer (1 or 2).

dmiller5

Quote
Despite its name, the analogWrite() function actually generates a digital PWM signal on pins 9, 10 or 11: http://www.arduino.cc/en/Reference/AnalogWrite

It's currently at 30 KHz, but you could change it with some 'magic' code to adjust the comparison register on the associated timer (1 or 2).


Ahh I can't believe I missed that page. Thank you very much for the response. It is exactly what I needed.

Dan

Where is the magic code? how can I do this? This sounds exactly like what I want. a controlled PWM frequency

p


simple stuff../ code correction..
how do I add an input value (because of pushbutton experiment) when using Knight Rider to create blinking sequence for LEDs.  

-im using the digitalWrite(pinNum,HIGH/LOW) and delay(time) example of the Knight Rider.

-later on I would wish to add a sound sensor

here's the code i was trying with,,

int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;

int timer= 100;

int pressurepad = 7; //choose the input pin (for a pushbutton)
int pressurepadd = 6;  

int val = 0;      // variable for reading the pin status

void setup() {
 pinMode (pin2, OUTPUT);  // declare LED as output
 pinMode (pin3, OUTPUT);  // declare LED as output
 pinMode (pin4, OUTPUT);  // declare LED as output
 pinMode (pin5, OUTPUT);  // declare LED as output

 pinMode(pressurepad, INPUT);    // declare pushbutton as input
 pinMode(pressurepadd, INPUT);    // declare pushbutton as input
}

void loop()
{
 val = digitalRead(pressurepad);  // read input value
 val = digitalRead(pressurepadd);  // read input value



if (val == LOW)
{                 //check if the input is HIGH (button released)        
   digitalWrite(pin2, HIGH);  
   delay (100);
   digitalWrite(pin2, LOW);
   delay(100);
   
   
   digitalWrite(pin3, HIGH);  
   delay (100);
   digitalWrite(pin3, LOW);
   delay(100);
   
   
   digitalWrite(pin4, HIGH);
   delay (100);
   digitalWrite(pin4, LOW);
   delay(100);
   
   
   digitalWrite(pin5, HIGH);
   delay (100);
   digitalWrite(pin5, LOW);
   delay(100);
   
     
   digitalWrite(pin5, HIGH);
   delay(100);
   digitalWrite(pin5, LOW);
   delay (100);
   
   
   digitalWrite(pin4, HIGH);
   delay(100);
   digitalWrite(pin4, LOW);
   delay (100);
   
   
   digitalWrite(pin3, HIGH);
   delay(100);
   digitalWrite(pin3, LOW);
   delay(100);

}


 delay (100);
}  


many thanks,
p


mellis

rogwabbit: see this thread for more details: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1170282999/1

I'm hoping to add a function to set the PWM frequency soon.

Go Up