Jump to content
43oh

Acrylic dragon


Recommended Posts

I'm not sure I would consider this a "project" other than to say "I have this and it doesn't work anymore so what can I do?"

 

Acrylic dragon:

8168916759_456996fa46_z.jpg

 

8168947378_b5080aab80_z.jpg

 

 

(pumpkin seeds not included)

 

That dragon came as a block setting on top of a purdy plastic base, asking for 3 AA batteries. It worked for around

a year or so, then just died.

 

So now that I'm trying to learn more things, I thought that I shouldn't just 'toss' out ideas for projects, but maybe actually make something.

 

 

So, if you can't already tell, I'm looking at having 1 (maybe 2) green LED's lighting up the "dragon", and maybe an amber one in there too- has to be realistic, right?

 

The "interesting" part, in my opinon is the other LED's on the proto-board: 2 red and one "blue": they will illuminate the "fire" being breathed by the dragon.

Link to post
Share on other sites

Blatantly stolen from others. ;-)

http://justinstech.o...rgb-flower-pot/

http://forum.43oh.co...1-pwm-with-wdt/

 

I didn't even bother removing most of the "unused" or commented out code... other than...

I couldn't get the code working properly with WDT as an interrupt, so I moved code to a wasteful "while" loop in main().

(not really even sure I need signal.h included... but I haven't commented it out yet.)

 

The #defines for UP, DOWN, and HOLD in the original code were declared as hex (0x01, etc), which caused problems, but changing them to INT: 0, 1, 2, fixed some issues... but I can't say that would be true for everyone.

 

This is CCS 5.2.1 code.

 

 

//includes
#include <msp430g2553.h>
#include <signal.h> //add for interrupt
//Defines
#define UP 0
#define DOWN 1
#define HOLD 2
#define PERIOD 40 //sets period length-- PERIOD x interval length
//variables
volatile int millsecs = 0;
volatile int counter2 = 0;
//volatile int counter3 = 0;
volatile int led_red = 1;
volatile int led_green = 1;
volatile int led_blue = 1;
volatile int red = UP;
volatile int blue = HOLD;
volatile int green = HOLD;
//start of main
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
//pin setup
P1DIR |= BIT5 + BIT4 + BIT3;
P1OUT |= BIT5 + BIT4 + BIT3;
while (1) {
++millsecs; //period and dutycycle counter
//period logic
if (millsecs == PERIOD) {
millsecs = 0;
//P1OUT |= BIT5 + BIT4 + BIT3;
++counter2;
}
//Duty cycle logic
if (millsecs == led_red) {
P1OUT ^= BIT3;
}
if (millsecs == led_green) {
P1OUT ^= BIT4;
}
if (millsecs == led_blue) {
P1OUT ^= BIT5;
}
//fade logic
if (counter2 == 5) {
counter2 = 0; //++counter3;
//power timer or how long till it turns off
//if (counter3 == 1000) { P1OUT = 0; _BIS_SR(LPM4_bits);}
switch (red) {
case UP:
if (++led_red == 199) {
 red = HOLD;
 green = UP;
 blue = DOWN;
}
break;
case DOWN:
if (--led_red == 0) {
 red = HOLD;
}
break;
case HOLD:
break;
} //end switch
switch (blue) {
case UP:
if (++led_blue == 199) {
 blue = HOLD;
 green = DOWN;
 red = UP;
}
break;
case DOWN:
if (--led_blue == 0) {
 blue = HOLD;
}
break;
case HOLD:
break;
} //end switch
switch (green) {
case UP:
if (++led_green == 199) {
 green = HOLD;
 red = DOWN;
 blue = UP;
}
break;
case DOWN:
if (--led_green == 0) {
 green = HOLD;
}
break;
case HOLD:
break;
} //end switch
} //end if
} // end while
} //end main

Link to post
Share on other sites

/me scratches head.

 

It's working now with this (sorry for the general lack of indents- it's just a copy/paste thing):

 

//includes
#include <msp430g2553.h>
#include <signal.h> //add for interrupt
//Defines
#define UP 0
#define DOWN 1
#define HOLD 2
#define PERIOD 120 //sets period length-- PERIOD x interval length
//variables
volatile int millsecs = 0;
volatile int counter2 = 0;
//volatile int counter3 = 0;
volatile int led_red = 1;
volatile int led_green = 1;
volatile int led_blue = 1;
volatile int red = UP;
volatile int blue = HOLD;
volatile int green = HOLD;
//start of main
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
//pin setup
P1DIR |= BIT5 + BIT4 + BIT3;
P1OUT |= BIT5 + BIT4 + BIT3;
while (1) {
++millsecs; //period and dutycycle counter
//period logic
if (millsecs == PERIOD) {
millsecs = 0;
//P1OUT |= BIT5 + BIT4 + BIT3;
++counter2;
}
//Duty cycle logic
if (millsecs == led_red) {
P1OUT ^= BIT3;
}
if (millsecs == led_green) {
P1OUT ^= BIT4;
}
if (millsecs == led_blue) {
P1OUT ^= BIT5;
}
//fade logic
if (counter2 == 5) {
counter2 = 0; //++counter3;
//power timer or how long till it turns off
//if (counter3 == 1000) { P1OUT = 0; _BIS_SR(LPM4_bits);}
switch (red) {
case UP:
if (++led_red == 199) {
 red = HOLD;
 green = UP;
 blue = DOWN;
}
break;
case DOWN:
if (--led_red == 0) {
 red = HOLD;
}
break;
case HOLD:
break;
} //end switch
switch (blue) {
case UP:
if (++led_blue == 199) {
 blue = HOLD;
 green = DOWN;
 red = UP;
}
break;
case DOWN:
if (--led_blue == 0) {
 blue = HOLD;
}
break;
case HOLD:
break;
} //end switch
switch (green) {
case UP:
if (++led_green == 199) {
 green = HOLD;
 red = DOWN;
 blue = UP;
}
break;
case DOWN:
if (--led_green == 0) {
 green = HOLD;
}
break;
case HOLD:
break;
} //end switch
} //end if
} // end while
} //end main

 

But I don't like the "speed" of the blinky's.

Link to post
Share on other sites

FWIW, I did combine several increments / decrements into the conditional statement(s).

 

I.e.- what I was originally:

case UP:

++led_red;

if (led_red == 199) {

red = HOLD;

green = UP;

blue = DOWN;

}

 

turned in to:

case UP:

if (++led_red == 199) {

red = HOLD;

green = UP;

blue = DOWN;

}"

 

 

 

If I shouldn't have done that, please let me know.

Link to post
Share on other sites

hmmmm... that code looks familar......lol

This is not the code you're looking for. ;)

Yes that should work.

 

I really should redo that code for the newer mspggcc, and clean it up a bit, and give an option for timer_a or WDT

I suffer from delusions of grandeur and often over-extend my abilities. Having code that didn't work right out of the box made me go look for things.

 

I think I worked at least some of it out, no?

 

What do you think of the video?

Link to post
Share on other sites

I just watched the video, looks very nice.

 

I love the how fast it cycles, and how the dragon lights up. Cant wait to see your finished piece.

 

Very Cool and Great work!!

 

As for the code, that was one of my first msp430 projects I took on, and I used an antiquated version of mspgcc that was not compatible with CCS or IAR or even the newer mspgcc. But it does show a simple way to create SW PWM.

I am very happy that it is being reused :)

 

Keep up the good work.

Link to post
Share on other sites

Decided to simplify the circuit a bit since the base for the acrylic is little more than 2.5 inches on a side and around 1 inch tall... and contains the batteries- 3 AAA.

 

The circuit originally had each LED switched through a 2n3904 transistor. Considering I'm using 420 ohm resistors on the power side (they're what I have on hand), it seemed unnecessary to keep the transistors. I could see using them if I were switching a string of LED's but as it is, one pin runs one LED so everything should be fine.

 

I'm going to let it run overnight to see how things go though since the first iteration didn't have the transistors or resistors inline and it kept blowing the red LEDs; blue, yellow and green don't seem to mind the current.

 

As it stands the circuit is like this... sorry for not having a proper schematic, using the Launchpad board powered by USB:

V+ for the 4 LED's is coming from the VCC pin on the board (lower right, next to reset button) with 420 ohm resistors on each LED.

GND for the green LED cathode is coming from a GND pin on the board (lower right, next to reset button).

P1.3 - P1.5 are switching 3 other LED's cathodes- as of now, 2 red and 1 blue; may change.

 

Battery operation may be an issue though, so something else to work on.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...