int button_C = 2; //set button1 at pin 2
int button_D = 3; //set button2 at pin 3
int button_E = 4; //set button3 at pin 4
int button_F = 5; //set buuton4 at pin 5
int button_G = 6; //set buuton5 at pin 6
int button_A = 7; //set button6 at pin 7
int button_B = 8; //set button7 at pin 8
int button_Cup = 9; //set buuton8 at pin 9
int speaker = 13; //set buzzerPin at pin 13
int buttonstate_C = 0; //When button1 isn't pressed its state is zero
int buttonstate_D = 0; //When button2 isn't pressed its state is zero
int buttonstate_E = 0; //When button3 isn't pressed its state is zero
int buttonstate_F = 0; //When button4 isn't pressed its state is zero
int buttonstate_G = 0; //When button5 isn't pressed its state is zero
int buttonstate_A = 0; //When button6 isn't pressed its state is zero
int buttonstate_B = 0; //When button7 isn't pressed its state is zero
int buttonstate_Cup = 0; //When button8 isn't pressed its state is zero
//NOTES 'c' , 'd', 'e', 'f', 'g', 'a', 'b', 'C'
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; //freq
int Cur_tone = 0; //sets the variable Cur_tone at 0
void setup()
// put your setup code here, to run once:
{
pinMode(button_C, INPUT); //button1 is an imput
pinMode(button_D, INPUT); //button2 is an imput
pinMode(button_E, INPUT); //button3 is an imput
pinMode(button_F, INPUT); //button4 is an imput
pinMode(button_G, INPUT); //button5 is an imput
pinMode(button_A, INPUT); //button6 is an imput
pinMode(button_B, INPUT); //button7 is an imput
pinMode(button_Cup, INPUT); //button8 is an imput
pinMode(speaker, OUTPUT); //The buzzerpin is an output
}
void loop()
// put your main code here, to run repeatedly:
{
buttonstate_C = digitalRead(button_C); //the state of the button is is button1
buttonstate_D = digitalRead(button_D); //the state of the button is is button2
buttonstate_E = digitalRead(button_E); //the state of the button is is button3
buttonstate_F = digitalRead(button_F); //the state of the button is is button4
buttonstate_G = digitalRead(button_G); //the state of the button is is button5
buttonstate_A = digitalRead(button_A); //the state of the button is is button6
buttonstate_B = digitalRead(button_B); //the state of the button is is button7
buttonstate_Cup = digitalRead(button_Cup); //the state of the button is is button8
if((buttonstate_C == HIGH) || (buttonstate_E == HIGH) ||
(buttonstate_G == HIGH) || (buttonstate_D == HIGH) ||
(buttonstate_F == HIGH) || (buttonstate_A == HIGH) ||
(buttonstate_B == HIGH) || (buttonstate_Cup == HIGH) ) //if button1state is high OR button2state is high OR...
{
if (buttonstate_C == HIGH) //if button1 is pressed
{
Cur_tone = tones[0]; //play note 0
}
if (buttonstate_E == HIGH) //if button2 is pressed
{
Cur_tone = tones[1]; //play note 1
}
if (buttonstate_G == HIGH) //if button3 is pressed
{
Cur_tone = tones[2]; //play note 2
}
if (buttonstate_D == HIGH) //if button4 is pressed
{
Cur_tone = tones[3]; //play note 3
}
if (buttonstate_F == HIGH) //if button5 is pressed
{
Cur_tone = tones[4]; //play note 4
}
if (buttonstate_A == HIGH) //if button6 is pressed
{
Cur_tone = tones[5]; //play note 5
}
if (buttonstate_B == HIGH) //if button7 is pressed
{
Cur_tone = tones[6]; //play note 6
}
if (buttonstate_Cup == HIGH) //if button8 is pressed
{
Cur_tone = tones[7]; //play note 7
}
digitalWrite(speaker, HIGH); //send massage though pin 13 and turn buzzer on
delayMicroseconds(Cur_tone); //wait for this ong
digitalWrite(speaker, LOW); //turn back off
delayMicroseconds(Cur_tone); //wait for next note
}
else //in case no button is pressed , close the piezo
{
digitalWrite(speaker, LOW); //if not button is pressed play no note
}
}
For this project we had to create our own code to program a Arduino Board. My partner and I decided to create an 8 button piano. We had to learn how to create circuits, draw circuit diagrams, program, and code. To learn these things went though many packets that explained how to do everything.
CONTENT:
REFLECTION:
I really enjoyed this project, except for the problems my partner and I encountered. One problem we had was the buzzer constantly played a note. We could not find out how to make the buzzer stop playing a note when no buttons were pressed. Another problem that we encountered was you had to press one button for a note, then one and two for another, so on so forth. When all buttons were pressed the buzzer turned off. The final problem we encountered was the 4th and 6th button did not create an new note when pressed sequentially. Even with all the problems we had we did have some positive experiences. We learned a huge amount of information. Whether we will be able to apply this information to a job later in life or we apply this information to a hobby like programing. Another positive we had was finishing our code. This was a huge achievement for us because all the problems we had.
CONTENT:
- Circuit - A complete loop made of conductors from one side of a power source to the other
- Parallel Circuit - Current has multiple routes it could take
- Series Circuit - The current goes through multiple resistances in a row
- Resistance - An obstacle to a current that weakens, reduces, or slows current. This is measured in Ohms
- Current - The flow of electricity from positive to negative (from one side of power source to the other). This is measured in amps by an ammeter
- Voltage - The push or pull of electricity; the "drop" of electricity across a resistor. This is measured in volts. The voltage in a circuit is equivalent to the current in the same circuit multiplied by the resistance.
- Power - The brightness of a bulb. This is measured in watts.
REFLECTION:
I really enjoyed this project, except for the problems my partner and I encountered. One problem we had was the buzzer constantly played a note. We could not find out how to make the buzzer stop playing a note when no buttons were pressed. Another problem that we encountered was you had to press one button for a note, then one and two for another, so on so forth. When all buttons were pressed the buzzer turned off. The final problem we encountered was the 4th and 6th button did not create an new note when pressed sequentially. Even with all the problems we had we did have some positive experiences. We learned a huge amount of information. Whether we will be able to apply this information to a job later in life or we apply this information to a hobby like programing. Another positive we had was finishing our code. This was a huge achievement for us because all the problems we had.