Instructables

How to make LED Fader using Digispark

Picture of How to make LED Fader using Digispark
top.jpg
led.jpg
Resister labelled.jpg
new-2.jpg
spreadsheet.jpg
https://www.dropbox.com/s/zj1mg9ewo62ttw7/animoto_high_res.mp4

MATERIALS REQUIRED

(In order)
item
supplier
Cat #
quantity

 
220 ohm resistor
digikey.com
220QBK-ND
3

 
RGB LED
digikey.com
754-1492-ND
1

 
Female header 3 pin
digikey.com
S7001-ND
1

 
Female header 6 pin
digikey.com
S7004-ND
1

 
Rectangular Connectors - Headers, Male Pins
digikey.com
S1011E-06-ND
1

 
Rectangular Connectors - Headers, Male Pins
digikey.com
S1011E-03-ND
1

 
PC DUAL-MINI BOARD
thesource.ca
2760148
1

 
Digispark development board
digistump.com
n/a
1

 
optional instead of buying components seperately
 
 
Digispark Starter kit
dgistump.com
has everything you need
1

 

ARDUINO BOARD IDE 1.0.3 CODE

//Declare all variables

int LED1;
int LED2;
int LED3;
int p0=0;
int p1=1;
int p4=4;
float x;
float r;
float g;
float b;
 
// the setup routine runs once when you press reset;
 
void setup() {     
Serial.begin(9600);  //start serial interface
 // initialize the digital pin as an output.
 pinMode(p0, OUTPUT); //sets up pin 0 for pwm
 pinMode(p1, OUTPUT); //sets up pin 1 for pwm
 pinMode(p4, OUTPUT); //sets up pin 4 for pwm
 digitalWrite(p0, HIGH);   // turn the LED o
 delay(1000); //delay for 1 second
 digitalWrite(p1, HIGH);
 delay(1000);
  digitalWrite(p4, HIGH);
 delay(1000);               // wait for a second
 digitalWrite(p0, LOW);
 delay(1000);   // turn the LED off by making the voltage LOW
 digitalWrite(p1, LOW);
  delay(1000);
  digitalWrite(p4, LOW);
 delay(1000);   
}
 
// the loop routine runs over and over again forever:
void loop() {
 for (int i=0; i<360; i++)
 {


//convert into a float to calculate r,g,b ( increase amplitute by multiplying by 127 and make positive by adding 1)

   x=float(i);
   r=127*(sin(x/180*PI)+1);
   g=127*(sin(x/180*PI+3/2*PI)+1);
   b=127*(sin(x/180*PI+0.5*PI)+1);
   
//convert flaot r,g,b to integer and assisting values to LED
    LED1= int(r);
   LED2= int(g);
   LED3= int(b);
   
//write LED levels to p0, p1, p4 (ASSIGN PWM values to LEDs)
    analogWrite (p0,LED1);
   analogWrite (p1,LED2);
   analogWrite (p4,LED3);
   
//wait for 1/100 of a second
    delay(100);}
}



In this project a number from 0-255 is used to represent 0%-100% duty cycle (brightness), sine function is used to generate it. Digispark uses sine function to generate the PWM (pulse width modulation). We convert the radians to degree's for the red, green, blue cycles. This is used to change the language for the computer to understand.



How to build

-Cut out an 8x9 hole square hole from the perf board
-Solder female header pins to DigiSpark
-Solder the bits ( male header pins, resistors, RGB LED(longest leg is your ground)
- The resistors are soldered to the perf board  in the PWM pins 1 and 4
-Then solder the resistors to the LED legs
-Solder the longest leg of the LED (ground) to the ground pin, cover the wire with insulation to avoid shorting out.
-Then use the Arduino 1.0.3 program to write your code (provided above) to program your PWM to your chip
-Plug in and play and your ready to go with your LED fader


 

bobricius1 month ago

Hi, you can try my digispark clone with onboard RGB led https://www.tindie.com/products/bobricius/picoduino/

Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!