Final Project: Glowstaff

For my final project, I decided to make a collapsable glowstaff. It can break down into three pieces and the middle piece could take a glow head for each end or a fire head for each end. In order to make the connection between the different pieces, I used a rod that was threaded on one side and epoxied on the other side. I started with aluminum tubing and a small aluminium rod. I used a lathe to turn the aluminium rod down so that it fit into the epoxy side. I used a tap and die to make the threaded connection with the lathe for alignment. I used an aluminium putty epoxy to affix the permanent side of the connection into place.

For the head of the staff, I planned to make my circuit with the copper sticker on the end of the end pieces of aluminium and then cast over it. I designed a new board in eagle, adding a hardware button debouncer. I cut out my circuit with the vinyl cutter on copper sticker. It took me about twenty tries to get a usable circuit. I used another piece of vinyl to separate the copper from the aluminium tubing. I followed Nadya's instructables article for this part, which recommends using transfer paper to put the circuit in the final spot and then weed out the excess copper from there.

Once, I populated my board on the end of my aluminium tubing, I tried to program it with my updated LED code. The board wouldn't program so I had to debug it. With the multimeter I determined that VCC and GND were connected but I couldn't figure out why. I spent about three hours debugging my board with the multimeter and removing certain parts to determine what was causing the short. It turned out that I had accidentally misread the pinout of the omamp and wired V- to VCC and V+ to GND. This had connected the VCC and GND nodes. To fix this problem, I did some intensive recontruction by cutting out new traces by hand to reroute the messed up section of the board.

For the casting part of the project, I was going to use Smooth-On SORTA-CLEAR 37. I CADed a negative of the head in Rhino and used the Shopbot to mill it out fo machineable wax. The wax mold fits around the end of the staff to allow the head to be cast over and around the circuit.

I updated code from the input and output devices weeks to include interrupts for the button push instead of checking in each interation of the main while loop.

//
//
// glowstaff.c
//
// RGB LED software PWM hello-world
//
// Template taken from:
// Neil Gershenfeld
// 11/10/10
//
// (c) Massachusetts Institute of Technology 2010
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose. Copyright is
// retained and must be preserved. The work is provided
// as is; no warranty is provided, and users accept all
// liability.
//
// Adapted by
// Liz Schell
// 11/20/15
//

#include 
#include 

#define output(directions,pin) (directions |= pin) // set port direction for output
#define input(directions,pin) (directions &= ~pin)
#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 red_port PORTB
#define green_port PORTA
#define blue_port PORTA
#define led_direction DDRB
#define red (1 << PB2)
#define green (1 << PA7)
#define blue (1 << PA3)

#define button_pin PINA
#define button (1 << PA2)

#define off (0)
#define rainbow_fade (1)
#define fire_fade (2)
#define white_blink (3)
#define blue_solid (4)
#define green_blink (5)

//int button_press(press) {
//  if (counter == 1000) {
//      counter = 0;
//      return 1;
//  }
//  else {
//  if (pin_test(button_pin, button))
//      int counter += 1;
//  else 
//      counter = 0;
//  return 0;
//  }
//}

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(red_port, red);
   output(DDRB, red);
   set(green_port, green);
   output(DDRA, green);
   set(blue_port, blue);
   output(DDRA, blue);
   input(DDRA,button);
   set(button_pin,button);

    int sequence = off;
//    int counter = 0;

while(1){
    while (0 != pin_test(button_pin,button)){
       _delay_ms(2);
    }

    while (0 == pin_test(button_pin, button)){
    if (sequence==5){
            sequence = 0;
            }
        else{
            sequence += 1;
            }
    }

    while (sequence==off){
        set(red_port,red);
        set(green_port,green);
        set(blue_port,blue);
     }

    while (sequence==rainbow_fade){
       //
       // off -> red
       //
//      for (count = 0; count < 255; ++count) {
//         set(red_port,red);
//         for (pwm = count; pwm < 255; ++pwm)
//            PWM_delay();
//         clear(red_port,red);
//         for (pwm = 0; pwm < count; ++pwm)
//           PWM_delay();
//         }
      //
      // red -> green
      //
      for (count = 0; count < 255; ++count) {
         clear(red_port,red);
         set(green_port,green);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         set(red_port,red);
         clear(green_port,green);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }
      //
      // green -> blue
      //
      for (count = 0; count < 255; ++count) {
         clear(green_port,green);
         set(blue_port,blue);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         set(green_port,green);
         clear(blue_port,blue);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }
      //
      // blue -> red
      //
      for (count = 0; count < 255; ++count) {
         clear(blue_port,blue);
         set(red_port,red);
         for (pwm = count; pwm < 255; ++pwm)
            PWM_delay();
         set(blue_port,blue);
         clear(red_port,red);
         for (pwm = 0; pwm < count; ++pwm)
            PWM_delay();
         }

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

    while(sequence==fire_fade){
        //red->yellow
        for (count = 0; count < 255; ++count) {
            set(green_port,green);
            for (pwm = count; pwm < 255; ++pwm)
                PWM_delay();
            clear(green_port,green);
            for (pwm = 0; pwm < count; ++pwm)
                PWM_delay();
            }
        //yellow->red
        for (count = 0; count < 255; ++count){
            clear(green_port,green);
            for (pwm = count; pwm < 255; ++ pwm)
                PWM_delay();
            set(green_port,green);
            for (pwm = 0; pwm < count; ++pwm)
                PWM_delay();
            }

        }//fire_fade

    while(sequence==white_blink){
        //on->off
        for (count = 0; count < 255; ++count) {
            clear(blue_port,blue);
            clear(green_port,green);
            clear(red_port,red);
            for (pwm = count; pwm < 255; ++pwm)
                PWM_delay();
            set(blue_port,blue);
            set(green_port,green);
            set(red_port,red);
            for (pwm = 0; pwm < count; ++pwm)
                PWM_delay();
            }

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