Fab Academy 2013

Output Devices

RGB LED

To power the board I used a FTDI connected to a protoboard, to connect the GND and VCC FTDI pins to the RGB LED GND and VCC pins.

Electronics production

Files for the RGB Led board production were dowloaded from the output device site.

Components needed to build the Hello LED RGB board are:

* ATTiny45A

* 6 pin header

* 4 pin header

* 3-Terminal regulator (5V)

* RGBLED

* Resister 10K

* 2 Resister 1K

* Resister 499

* Capacitor 1uF

Programming the board

Programming the board as usually on the terminal with AVR ISP. Files here:

* http://academy.cba.mit.edu/classes/output_devices/RGB/hello.RGB.45.c

* Make file

Understanding Neil's code

I wrote some comments on Neil's code to a better understanding of what the board is doing.

 
        /
// hello.RGB.45.c
//
// RGB LED software PWM hello-world
//
// Neil Gershenfeld
// 11/10/10
//
// (c) Massachusetts Institute of Technology 2010
// Permission granted for experimental and personal use;
// license for commercial sale available from MIT.
//

#include 
#include 

#define output(directions,pin) (directions |= pin) // set port direction for output
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define PWM_delay() _delay_us(25) // PWM delay

#define led_port PORTB // Define PORTB to led_port
#define led_direction DDRB // Define DDRB to led_direction
#define red (1 << PB1) // Set PB1 is named "red" 
#define green (1 << PB0) // Set PB0 is named "green"
#define blue (1 << PB2)// Set PB2 is named "blue"

int main(void) {
   //
   // main
   //
   unsigned char count, pwm;
   //
   // set clock divider to /1
   //
   CLKPR = (1 << CLKPCE);
   CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
   //
   // initialize LED pins
   //
   set(led_port, red); // set "red" port to " High"
   output(led_direction, red); // set "red" port to the output
   set(led_port, green); // set "green" port to " High"
   output(led_direction, green); //  set "green" port to the output
   set(led_port, blue); // set "blue" port to " High"
   output(led_direction, blue); // set "blue" port to the output
   //
   // main loop
   //
   while (1) {
      //
      // off -> red
      //
      for (count = 0; count < 255; ++count) { // Turn on LED on red
         clear(led_port,red);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         set(led_port,red);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }
      //
      // red -> green 
      //
      for (count = 0; count < 255; ++count) {
         set(led_port,red);
         clear(led_port,green);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         clear(led_port,red);
         set(led_port,green);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }
      //
      // green -> blue
      //
      for (count = 0; count < 255; ++count) {
         set(led_port,green);
         clear(led_port,blue);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         clear(led_port,green);
         set(led_port,blue);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }
      //
      // blue -> on
      //
      for (count = 0; count < 255; ++count) {
         set(led_port,blue);
         clear(led_port,green);
         clear(led_port,red);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         set(led_port,blue);
         set(led_port,green);
         set(led_port,red);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }

      //
      // on -> off
      //
      for (count = 0; count < 255; ++count) {
         set(led_port,blue);
         set(led_port,green);
         set(led_port,red);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         clear(led_port,blue);
         clear(led_port,green);
         clear(led_port,red);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }
      }
   }