Go Down

Topic: Help me free the fireflies, please. (Read 514 times) previous topic - next topic

Mortalsphere

Apr 08, 2013, 03:22 pm Last Edit: Apr 08, 2013, 09:00 pm by Coding Badly Reason: 1
I trying to build this project( http://www.instructables.com/id/Jar-of-Fireflies/#intro ). Instead of using the surface mount components I've decide to go with through hole. This meant building a new PCB.

At any rate on this particular instructables they don't provide any code that I could see. I did happen to find code that ran the same kind of thing on the Uno. So I took that and tried to adapt it to the ATtiny.

I flashed the ATtiny with my Uno. Following the instructions here ( http://hlt.media.mit.edu/?p=1229 ) I built the circuit on my solder-less breadboard and it isn't working at all. This is the first time I've done this and I don't know if some of my code isn't compatible with in the ATtiny or if the circuit design is faulty.

Here's my code:
Code: [Select]
int PWMP3 = 3;
int PWMP6 = 6;
int led2 = 2;
int led7 = 7;
int led5 = 5;

void song1() {
 analogWrite(PWMP3, 170);
 analogWrite(PWMP6, 170);
 delay(50);
 analogWrite(PWMP3, 125);
 analogWrite(PWMP6, 125);
 delay(100);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
 delay(1000);
 analogWrite(PWMP3, 245);
 analogWrite(PWMP6, 245);
 delay(500);
 analogWrite(PWMP3, 170);
 analogWrite(PWMP6, 170);
 delay(50);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
}

void song2() {
 analogWrite(PWMP3, 245);
 analogWrite(PWMP6, 245);
 delay(50);
 analogWrite(PWMP3, 170);
 analogWrite(PWMP6, 170);
 delay(1500);
 analogWrite(PWMP3, 245);
 analogWrite(PWMP3, 245);
 delay(500);
 analogWrite(PWMP3, 170);
 analogWrite(PWMP6, 170);
 delay(500);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
}

void song3() {
 analogWrite(PWMP3, 170);
 analogWrite(PWMP6, 170);
 delay(50);
 analogWrite(PWMP3, 150);
 analogWrite(PWMP6, 150);
 delay(250);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
 delay(200);
 analogWrite(PWMP3, 165);
 analogWrite(PWMP6, 165);
 delay(50);
 analogWrite(PWMP3, 145);
 analogWrite(PWMP6, 145);
 delay(250);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
 delay(200);
 analogWrite(PWMP3, 160);
 analogWrite(PWMP6, 160);
 delay(50);
 analogWrite(PWMP3, 140);
 analogWrite(PWMP6, 140);
 delay(250);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
 delay(200);
 analogWrite(PWMP3, 155);
 analogWrite(PWMP6, 155);
 delay(50);
 analogWrite(PWMP3, 135);
 analogWrite(PWMP6, 135);
 delay(250);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
 delay(200);
 analogWrite(PWMP3, 150);
 analogWrite(PWMP6, 150);
 delay(50);
 analogWrite(PWMP3, 130);
 analogWrite(PWMP6, 130);
 delay(250);
 analogWrite(PWMP3, 0);
 analogWrite(PWMP6, 0);
 delay(1000);
 
}

void setup() {
 /* Philip Millies Fading Fireflies / 2 pin PWM control. */
 pinMode(PWMP3, OUTPUT);
 pinMode(PWMP6, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led5, OUTPUT);
 pinMode(led7, OUTPUT);
}

void loop() {
 digitalWrite(led2, LOW);
 digitalWrite(led5, HIGH);
 digitalWrite(led7, HIGH);
 song1();
 delay(2500);
 digitalWrite(led2, HIGH);
 digitalWrite(led5, LOW);
 digitalWrite(led7, HIGH);
 song2();
 delay(2500);
 digitalWrite(led2, HIGH);
 digitalWrite(led5, HIGH);
 digitalWrite(led7, LOW);
 song3();
 delay(2500);
}



Moderator edit: [code] [/code] tags added.

Erni

You are using the physical pin numbers as far as I can see.

See this cheet sheet for the right numbers to use in your sketch:

http://www.akafugu.jp/posts/resources/reference-sheet/

PWM pins are 0,1 and 4, atleast if you use this core:

https://code.google.com/p/arduino-tiny/




Mortalsphere

Thank you very much for your quick reply. I will make the changes to my code and see if that helps.

How are the core on google code different from the one I downloaded via the MIT tutorial?

Erni

Quote
How are the core on google code different from the one I downloaded via the MIT tutorial?


I don't know the core from MIT, there might be difference in pin numbers and number of pwm pins.

Anyway, you will propably need this too:

https://github.com/TCWORLD/ATTinyCore/tree/master/PCREL%20Patch%20for%20GCC

It fixes a bug for sketches > 4 kb

Mortalsphere

#4
Apr 08, 2013, 04:11 pm Last Edit: Apr 08, 2013, 04:25 pm by Mortalsphere Reason: 1
Ok, I have installed the core that you linked me to. I don't think I can use the other one cause one pwm pin is in the wrong place for my pcb to work correctly. Now I just need to flash it again.

My sketch is only 1.7 kbytes, so it should be ok.

UPDATE: It works! Thankyou very much for you help. Now I just need to flash 39 more tinys.

Erni

Glad you had it working, I can see you have some work ahead of you with 39 Tiny's

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy