Pages: 1 [2]   Go Down
Author Topic: attiny85 with 3 PWN pins  (Read 13268 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have all 3 LEDs working now,

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



Code:
  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.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The short form is, vary these three lines:

Code:
  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
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have all 3 LEDs working now,

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



Code:
 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.
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Pages: 1 [2]   Go Up
Jump to: