Description:The thing I participated in for this project was the building where I built almost everything while my partner did the code we would start off by picking one of the builds to make as after that I would build the thing make sure its all good where I would go and look over it to make sure everything is fine until my partner starts creating the code where I wait for him to finish making it and then check if it works and we would repeat that process until everything was done.
Reflection:I believe I did my part in the project as I did the building and looking over the the things I want to keep working on is doing my part in the project
Code:
Arduino 1:
int speakerPin = 10; // The pin that buzzer is connected to
int firstKeyPin = 2;
int secondKeyPin = 3;
int thirdKeyPin = 4;
int buzzerPin = 10;
void setup() {
// Set the output pin for the speaker
pinMode(speakerPin, OUTPUT);
pinMode(firstKeyPin, INPUT_PULLUP);
pinMode(secondKeyPin, INPUT_PULLUP);
pinMode(thirdKeyPin, INPUT_PULLUP);
// Set the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
// Set LED pins as outputs
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
// Play the Happy Birthday song
digitalWrite(13, HIGH); // Turn on the LED
delay(1000); // Wait for one second
digitalWrite(13, LOW); // Turn off the LED
delay(1000); // Wait one second
digitalWrite(12, HIGH); // Turn on the LED
delay(1000); // Wait for one second
digitalWrite(12, LOW); // Turn off the LED
delay(1000); // Wait one second
digitalWrite(11, HIGH); // Turn on the LED
delay(1000); // Wait for one second
digitalWrite(11, LOW); // Turn off the LED
digitalWrite(9, HIGH); // Turn on the LED
delay(1000); // Wait for one second
digitalWrite(9, LOW); // Turn off the LED
digitalWrite(8, HIGH); // Turn on the LED
delay(1000); // Wait for one second
digitalWrite(8, LOW); // Turn off the LED
digitalWrite(7, HIGH); // Turn on the LED
delay(1000); // Wait for one second
digitalWrite(7, LOW); // Turn off the LED
play('g', 2); // ha
digitalWrite(13, HIGH); // Turn on the LED
play('g', 1); // ppy
play('a', 4); // birth
play('g', 4); // day
digitalWrite(13, LOW); // Turn off the LED
digitalWrite(7, HIGH); // Turn on the LED
play('C', 4); // to
play('b', 4); // you
play(' ', 2); // Pause for 2 beats
play('g', 2); // ha
play('g', 1); // ppy
digitalWrite(7, LOW); // Turn off the LED
digitalWrite(12, HIGH); // Turn on the LED
play('a', 4); // birth
play('g', 4); // day
play('D', 4); // to
play('C', 4); // you
digitalWrite(12, LOW); // Turn off the LED
play(' ', 2); // Pause for 2 beats
play('g', 2); // ha
play('g', 1); // ppy
digitalWrite(12, LOW); // Turn off the LED
digitalWrite(9, HIGH); // Turn on the LED
play('G', 4); // birth
play('E', 4); // day
play('C', 4); // dear
digitalWrite(9, LOW); // Turn off the LED
digitalWrite(9, HIGH); // Turn on the LED
play('b', 4); // your
play('a', 6); // name
digitalWrite(9, LOW); // Turn off the LED
play(' ', 2); // Pause for 2 beats
digitalWrite(10, HIGH); // Turn on the LED
play('F', 2); // ha
play('F', 1); // ppy
play('E', 4); // birth
digitalWrite(10, LOW); // Turn off the LED
digitalWrite(8, HIGH); // Turn on the LED
play('C', 4); // day
play('D', 4); // to
play('C', 6); // you
digitalWrite(8, LOW); // Turn off the LED
// After playing the song, wait for key presses to play tones
while (true) {
if (digitalRead(firstKeyPin) == LOW) { // If the first key is pressed
tone(buzzerPin, 262); // Play the frequency for c
} else if (digitalRead(secondKeyPin) == LOW) { // If the second key is pressed
tone(buzzerPin, 330); // Play the frequency for e
} else if (digitalRead(thirdKeyPin) == LOW) { // If the third key is pressed
tone(buzzerPin, 392); // Play the frequency for g
} else {
noTone(buzzerPin); // If no key is pressed, turn the buzzer off
}
}
}
// Function to play a note for a specified number of beats
void play(char note, int beats) {
int numNotes = 15; // Number of notes in our note and frequency array
// Note: these notes are in C major (no sharps or flats)
char notes[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B', ' '};
int frequencies[] = {131, 147, 165, 175, 196, 220, 247, 262, 294, 330, 349, 392, 440, 494, 0};
int currentFrequency = 0; // The frequency that we find when we look up a frequency in the arrays
int beatLength = 150; // The length of one beat (changing this will speed up or slow down the tempo)
// Look up the frequency that corresponds to the note
for (int i = 0; i < numNotes; i++) { // Check each value in notes from 0 to 14
if (notes[i] == note) { // Does the letter passed to the play function match the letter in the array?
currentFrequency = frequencies[i]; // Yes! Set the current frequency to match that note
}
}
// Play the frequency that matched our letter for the number of beats passed to the play function
tone(speakerPin, currentFrequency, beats * beatLength);
delay(beats * beatLength); // Wait for the length of the tone so that it has time to play
delay(50); // A little delay between the notes makes the song sound more natural
}
/* CHART OF FREQUENCIES FOR NOTES IN C MAJOR
Note Frequency (Hz)
c 131
d 147
e 165
f 175
g 196
a 220
b 247
C 262
D 294
E 330
F 349
G 392
A 440
B 494
*/
Arduino 2:
/*
SparkFun Inventor’s Kit
Circuit 4A-HelloWorld
The LCD will display the words "Hello World" and show how many seconds have passed since
the RedBoard was last reset.
This sketch was written by SparkFun Electronics, with lots of help from the Arduino community.
This code is completely free for any use.
View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-experiment-guide---v41
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
*/
#include <LiquidCrystal.h> //the liquid crystal library contains commands for printing to the display
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // tell the RedBoard what pins are connected to the display
void setup() {
lcd.begin(16, 2); //tell the lcd library that we are using a display that is 16 characters wide and 2 characters high
lcd.clear(); //clear the display
}
void loop() {
lcd.setCursor(0, 0); //set the cursor to the 0,0 position (top left corner)
lcd.print("Happy Birthday!"); //print hello, world! starting at that position
lcd.setCursor(0, 1); //move the cursor to the first space of the bottom row
lcd.print(millis() / 1000); //print the number of seconds that have passed since the last reset