WEEK10-OUTPUT DEVICES

I want to design a music lamp, music play by buzzer and the led blink at the same time.

Part 1 Design board

I will use usbtiny to program it, so I use attiny44, a buzzer and six led for my job.
1. Design the board by eagle.
Open the software and design the circuit diagram. There are two rows led, one row include three leds and they are parallel.
800x600
Set the components, and this need some time.
800x600 Board Download
2. Excport the picture and generate the cutting code.
Export the pictures of board. And open fabmodule then generate the code of trace.
800x600
Generate the code of outline.
800x600

Part 2 Cut board and solder

1. Cut by roland srm20
Waiting about 30 mins then the board was cut.
800x600
2. Solder.
It is easy to solder while you have good tools.
800x600

Part 3 Programming

1. I program it and put upload to the board.
It is programed by arduino. This is the code blow:
#define d1 262
#define d2 294
#define d3 330
#define d4 349
#define d5 392
#define d6 440
#define d7 494
#define w 100
#define h 50
#define q 25
int tune[] = {
  d1, d1, d5, d5,
  d6, d6, d5,
  d4, d4, d3, d3,
  d2, d2, d1,
  d5, d5, d4, d4,
  d3, d3, d2,
  d5, d5, d4, d4,
  d3, d3, d2,
  d1, d1, d5, d5,
  d6, d6, d5,
  d4, d4, d3, d3,
  d2, d2, d1
};
int dura[] = {
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
};
int lenth;
int tonepin=3;
int ledapin=7;
int ledbpin=2;
void setup() {
pinMode(tonepin,OUTPUT);
pinMode(ledapin,OUTPUT);
pinMode(ledbpin,OUTPUT);
lenth=sizeof(tune)/sizeof(tune[0]);
}
void loop() {
for(int i=0;i=0;j--)
{
analogWrite(7,j);
delay(500);
 } 
 delay(500);
digitalWrite(ledbpin,HIGH);    
delay(500); 
digitalWrite(ledbpin,LOW);    
delay(500);               
} 
    
2. Upload to board.
Something bad happened the board dont work as I want. The buzzer doesn't work and the only one led of every row. I use one red one green and one blue led as a row. Only the red led is on. Fortunately, the the led breath.
3. Check the problem.
I have check all of the led before I solder, and I check them again they are ok. Then I think maybe the current or voltage is not enough, the current out from the pin is 20mA. I short circuit the resistor for led. I found two of the led of every row worked. So the problem is not enough current. 0 Ω resistor will instead.
Check the buzzer, I only fine one buzzer in the lab, it is a piezo buzzer, it should sound after connect to power. I connect the power directly to buzzer then it sound. The buzzer is ok, so maybe the same problem, the power out from I/O pin is not enough. A amplifying circuit should be added. I found a buzzer with a amplifing circuit from another lab. I solder it to my board. A little urgly.
800x600
Upload to the board. It worked.
I want to control the two row led on the same time, I edit the code
        #define d1 262
#define d2 294
#define d3 330
#define d4 349
#define d5 392
#define d6 440
#define d7 494
#define w 100
#define h 50
#define q 25
int tune[] = {
  d1, d1, d5, d5,
  d6, d6, d5,
  d4, d4, d3, d3,
  d2, d2, d1,
  d5, d5, d4, d4,
  d3, d3, d2,
  d5, d5, d4, d4,
  d3, d3, d2,
  d1, d1, d5, d5,
  d6, d6, d5,
  d4, d4, d3, d3,
  d2, d2, d1
};
int dura[] = {
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
  w, w, w, w,
  w, w, w + w,
};
int lenth;
int tonepin=3;
int ledapin=7;
int ledbpin=2;
void setup() {
pinMode(tonepin,OUTPUT);  
pinMode(ledapin,OUTPUT);
pinMode(ledbpin,OUTPUT);
lenth=sizeof(tune)/sizeof(tune[0]);
}
void loop() {
for(int i=0;i=0;j--)
{
if(j>0)
 {analogWrite(7,j);
 if(j>127)
 {digitalWrite(ledbpin,HIGH);
 else
 digitalWrite(ledbpin,LOW);
 }
 delay(100);}
  } 
  delay(500); 
}
        
The light is show in the vedio below