Go Down

Topic: attiny85 with 3 PWN pins (Read 13 times) previous topic - next topic

Nick Gammon

Quote
I have all 3 LEDs working now,


You are only setting one pin as output, for one thing.




Code: [Select]

  for(int i = 0; i < 255; i++){
    digitalWrite(0, i);
    delay(50);
  }


Quote
but there is some really weird things going on with the timing. this code basically only produces an on and off state every 30seconds or so:


That's what digitalWrite does. Turn the pin on or off.
http://www.gammon.com.au/electronics

strykeroz

You'd probably like to look at analogWrite() if you are using hardware PWM.  Digitalwrite was needed in the software PWM example because it can be used on any pin, even those where analogWrite is unsupported.
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

hilukasz


The short form is, vary these three lines:

Code: [Select]

  OCR0A = 127;                   // duty cycle (50%)
...
  OCR0B = 63;                    // duty cycle (25%)
...
  OCR1B = 31;                   // duty cycle (25%)


They control the duty cycle. In the case of the first two, 100% is 255, and 0% is 0. The third one counts up to 127, so the duty cycle is half that (or change the line "OCR1C = 127;" to be "OCR1C = 255;" and they will all be the same).


Put your LEDs on pins 3, 5 and 6. Change the duty cycle as required and the LEDs will change brightness.


aha, ok that is very helpful. is this to save battery life? ie set duty cycle to half at 127
for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

hilukasz


Quote
I have all 3 LEDs working now,


You are only setting one pin as output, for one thing.




Code: [Select]

 for(int i = 0; i < 255; i++){
   digitalWrite(0, i);
   delay(50);
 }


Quote
but there is some really weird things going on with the timing. this code basically only produces an on and off state every 30seconds or so:


That's what digitalWrite does. Turn the pin on or off.


sorry I meant the original project I was working on. I used your references to get it working. It was the new library that fixed it.

Quote
That's what digitalWrite does. Turn the pin on or off.


hah... yeah you are totally right, I was silly and had digital instead of analog.
for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Go Up