Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Single Frequency, variable Duty cycle PWM on: May 23, 2010, 01:40:58 pm
I'm in the process of creating an LED array of 12 red LED's and 76 white LED's  (switched), with the hopes of varying the brightness. I've tried creating a 555 timer circuit (which I can never get working) to no avail. I wrote some code that will vary the Duty Cycle directly with the input analog value (ie resistor). Can anybody point out any problems or shortcuts that can be used?

int potPin=  5;
int ledPin = 11;
int val = 0;

void setup()
pinMode(ledPin, OUTPUT);   // sets the pin as output
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS22);    

void loop()
val = analogRead(potPin);    // read the value from the sensor
OCR2A = val;                 //Value of sensor denotes PWM duty cycle
analogWrite(ledPin, HIGH);   //Pulse LED pin with the OCR2A value

Pages: [1]