Digistump Forums
The Digispark => Digispark Project Ideas => Topic started by: seldenr on January 12, 2014, 04:22:30 pm
-
Hi,
I was just noticing that my new RGB shield from DigiStump only allows red and green to be on the PWM pins of the digispark. This means that blue must use software-PWM, which means no usb connection. I was wondering, would using P4's PWM compatibility work for the led? I would just cut the P2 Header off of the shield, and then solder a little jumper wire between the P2 and P4 spots on top. This way, I could program it using P4's PWM, and then the PWM signal would jump over to the right slot that is wired to the led.
Thanks for your input.
R
-
P4 wasn't used because it will interfere with USB
The DigiBlink example uses softPWM for the blue and USB at the same time without issue.
If you look at the source files for the RGB shield you'll see there are solder jumpers on the bottom that can be cut and joined to connect Blue to P4 if desired.
-
P4 wasn't used because it will interfere with USB
The DigiBlink example uses softPWM for the blue and USB at the same time without issue.
If you look at the source files for the RGB shield you'll see there are solder jumpers on the bottom that can be cut and joined to connect Blue to P4 if desired.
Ok. I looked at the software PWM example but I couldn't figure out how to use that for myself. Are there any clearer examples?
-
add this at the bottom of your sketch
void setBlue(Blue){
if(Blue == 0){
digitalWrite(2,LOW);
return;
}
else if(Blue == 255){
digitalWrite(2,HIGH);
return;
}
// On period
for (int x=0;x<Blue;x++){
digitalWrite(2,HIGH);
}
// Off period
for(int x=0;x<(255-Blue);x++){
digitalWrite(2,LOW);
}
}
call it form your sketch with setBlue(255); where 255 is the PWM value you want to use.
make sure your loop doesn't have any delays in it for this to work.
lots of other PWM methods out there for the attiny85 which may work to - or check out the littlewire (littlewire.cc) firmware which can be loaded onto the Digispark and has USB communication, a Ruby and C library, and softPWM