I am having an odd problem with an ATTINY85...I looked online and the ATTINY85 can do 3 PWM channels so I wired up a nightlight with this code:
// color swirl! connect an RGB LED to the PWM pins as indicated
// in the #defines
// public domain, enjoy!
#define REDPIN 0
#define GREENPIN 1
#define BLUEPIN 4
#define PIR A3
boolean human_detected = false;
unsigned long timer;
int r, g, b;
#define FADESPEED 5 // make this higher to slow down
void setup() {
pinMode(PIR, INPUT);
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 0);
//Serial.begin(9600);
timer = millis();
}
void loop() {
//Serial.print("Human detected: ");
//Serial.println(human_detected);
//We check the PIR sensor to see if it's on then call the
int sensor_status = digitalRead(PIR);
//Serial.print("PIR Reading: ");
//Serial.println(sensor_status);
if (sensor_status == 1) {
human_detected = true;
timer = millis();
}
if (human_detected) {
//Fade red
for (r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
for (r = 256; r > 0; r--) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN,0);
analogWrite(REDPIN,0);
//Fade green
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
for (g = 256; g > 0; g--) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN,0);
analogWrite(REDPIN,0);
//Fade blue
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
for (b = 256; b > 0; b--) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN,0);
analogWrite(REDPIN,0);
}
if (millis() - timer > 5000){
human_detected = false;
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN,0);
analogWrite(REDPIN,0);
}
}
The issue I am having is that the blue channel doesn't PWM at all. After everything goes dark after the green fade, there's a split second pause and then blue turns on for a short period and goes off...It doesn't alter the brightness at all. Can someone point me in the right direction?
Since I don't have a high voltage programmer and for my practical purposes it's a one way operation I have not changed any fuses, not until I get my nightlight working the way I want. I'll keep reading my MAKE book until I learn more. I was hoping it would not have to make a permanent change like that yet
The Digispark tiny85 uses the Bluebie boot loader and is designed to be programmed without the need of reset. Therefore, you can get 3 PWM and reprogram too.
dave-in-nj:
did you set the fuse for the 3rd channel ?
it defaults to the reset.
once you change the fuse setting you can only re-program with a high voltage programmer.
Wow. You are seriously full of shit. A quick check of the datasheet reveals the RESET pin is marked with...
psychephylax:
The issue I am having is that the blue channel doesn't PWM at all. After everything goes dark after the green fade, there's a split second pause and then blue turns on for a short period and goes off...It doesn't alter the brightness at all. Can someone point me in the right direction?
OMG! I really must stop drinking coffee and reading these posts Another coffee spew ... coffee does seem to clean the keyboard fairly well / Hopefully the moisture seal in the keyboard is working ! No matter though, I can buy another PC, but this humor is priceless!
Thank you for the link, I actually installed this core on my laptop and tried flashing the ATTINY85 with my code but it didn't even light up the LED strip. There are a few options in the board menu for ATTINY85 and I'm not quite sure which one to go with. The one thing I did was change the internal clock to 8 MHz so I went with the 8MHz option with internal oscillator and BOD disabled. I will try again and report back
Thanks! I was able to get it to mostly work (At least the PWM functionality)
I had to strip almost all the PIR and other code out to be able to test 3 channel PWM
#define REDPIN 0
#define GREENPIN 1
#define BLUEPIN 4
#define PIR 3
boolean human_detected = false;
unsigned long timer;
int r, g, b;
#define FADESPEED 10 // make this higher to slow down
void setup() {
pinMode(PIR, INPUT);
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 0);
}
void loop() {
for (r = 0; r < 255; r++) {
analogWrite(REDPIN, r);
analogWrite(GREENPIN, r);
analogWrite(BLUEPIN, r);
delay(FADESPEED);
}
}