Go Down

Topic: Klingon Proton Collector (Read 19533 times) previous topic - next topic

jameskirk


PaulRB

#46
Aug 26, 2014, 01:48 am Last Edit: Aug 26, 2014, 01:49 am by PaulRB Reason: 1
You're welcome!

Code: [Select]
/*
 Klingon Proton Collector Sketch
*/

int xleds = 2;
int levelled = 10;
int spkr = 4;
int xledDelay = 1000; // Controls the rate of the X-leds flashing

// the setup routine runs once when you press reset:
void setup() {                
 // initialize the digital pin as an output.
 pinMode(xleds, OUTPUT);
 pinMode(levelled, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
 analogWrite(levelled, map(xledDelay, 1000, 0, 0, 255));
 digitalWrite(xleds, HIGH);   // turn the LED on (HIGH is the voltage level)
 tone(spkr, 1000, 50);
 delay(xledDelay);               // wait for a second
 digitalWrite(xleds, LOW);    // turn the LED off by making the voltage LOW
 tone(spkr, 2000, 50);
 delay(xledDelay);               // wait for a second
 
 xledDelay -= (xledDelay) / 50; //increase the flashing speed a little
}

jameskirk

Well I got it hooked up kinda messy on this board...
It will be better when I get the new stuff in the mail...
Here's the link...
https://www.youtube.com/watch?v=jc9WCtTIx0Q
Next is to program it to the ATTiny85...
Thanks
Michael

PaulRB


Next is to program it to the ATTiny85...


I made a little vid for you. Sorry, some of the screen shots are blurred!

http://youtu.be/bVIOAWCRuwg

Detail of circuit below.

PaulRB

#49
Aug 28, 2014, 11:06 pm Last Edit: Aug 28, 2014, 11:10 pm by PaulRB Reason: 1
Well, I've got the whole KPC thing running on the tiny85.

Not without problems though. The reason is, I'm pretty sure, because of things called timers. Timers, as you would expect, allow the chip to measure short periods of time. In the sketch that we have running on the Nano uses a total of 3 timers:

1. for use by the tone() function, which uses a timer to create a particular pitched tone
2. for use by the analogWrite() function, which uses a timer to create the PWM signal to fade the leds
3. for use by the delay() function, which uses a timer to time each millisecond pause

The mega328 chip on the Nano has 3 timers. But the tiny85 only has 2! As a result, the tone() function would not work on the tiny.

So I had to write an extra function to make a beep.

http://youtu.be/t4QpinL3Pt0

You see a strange pulsating effect on the fading leds on this video. It looks cool, but unfortunately you don't see it with the naked eye. Must be to do with the frame rate of the camera vs the PWM frequency.

Code: [Select]
/*
 Klingon Proton Collector Sketch
*/

int xleds = 4;
int levelled = 1;
int spkr = 0;
int xledDelay = 1000; // Controls the rate of the X-leds flashing

// the setup routine runs once when you press reset:
void setup() {                
 // initialize the digital pin as an output.
 pinMode(xleds, OUTPUT);
 pinMode(levelled, OUTPUT);
 pinMode(spkr, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
 analogWrite(levelled, map(xledDelay, 1000, 0, 0, 255));
 digitalWrite(xleds, HIGH);   // turn the LED on (HIGH is the voltage level)
 beep(50, 50);
 delay(xledDelay);               // wait for a second
 digitalWrite(xleds, LOW);    // turn the LED off by making the voltage LOW
 beep(25, 100);
 delay(xledDelay);               // wait for a second
 
 xledDelay -= (xledDelay) / 50; //increase the flashing speed a little
}

void beep(byte d, byte l) {
 
 byte v;
 noInterrupts();
 for (byte i=0; i<l; i++) {
   digitalWrite(spkr, v);
   delayMicroseconds(d);
   v = !v;
 }
 interrupts();
}  


I said earlier I did not want to do it all for you, but it turns out I have. Hope its been an interesting introduction to Arduino for you, it entertained me for a couple of hours. Let us know how you get on and any problems you encounter.


jameskirk

As far as the capacitors on your board I can't get the .1J63
can I use these instead???
http://www.ebay.com/itm/100-x-0-1uF-50V-Ceramic-Disc-Capacitors-Free-Shipping-/280968355990?pt=LH_DefaultDomain_0&hash=item416b04e096
Also what size of capacitor is the black one you are using???
Thanks
Michael

PaulRB

Yes, any 0.1uF cap will be fine.

The anti-reset cap was a 10uF, but the value is not critical. Probably anything 1uF or above would work.

jameskirk

Here is a short clip of the programmed chip...
Not the final just the test...
http://vid1078.photobucket.com/albums/w495/jamestkirk1864/20140829_215605_zps635ee5c6.mp4
Can I program the chip with the board the way it is or do I need to
move it back to the other board and program it to the final version???
Thanks
Michael

PaulRB

If I understand what you're asking, then yes you can upload the final kpc sketch to the tiny85 now, then move the tiny85 to the other board and connect it up to the xleds, speaker etc.

jameskirk

I got it finally found out what I did wrong...
Thanks
Michael

PaulRB

So its working on the tiny85? Great!

That 0.1uF cap wasn't just for programming. It should be with the tiny on the final circuit, as close to the tiny's Vcc and GND pins as possible. (The other, larger, cap was just or programming).

jameskirk

#56
Aug 31, 2014, 07:12 pm Last Edit: Aug 31, 2014, 07:14 pm by jameskirk Reason: 1
Is there a way to get the single LEDs not to flash when the other 4 are blinking in there sequence???
Also there dim when it starts up and bright when it is done...
Thanks
Michael

PaulRB


Is there a way to get the single LEDs not to flash when the other 4 are blinking in there sequence???

They shouldn't be flashing. They are supposed to fade up gradually, like in the movie.


Also there dim when it starts up and bright when it is done...

They are fading up and flashing?

jameskirk

It is just a slight flash not a blink...
I see it in yours also...
I also didn't see but the 2 LEDs do get brighter as it gets fuller...
Thanks
Michael

PaulRB

Quote
You see a strange pulsating effect on the fading leds on this video. It looks cool, but unfortunately you don't see it with the naked eye. 


Is yours flashing to the naked eye? It shouldn't be...

Go Up