Hello there! My name is Michael and I'm completely new to the world of programming and of course, the world of Arduino.
ProjectAs you've already seen, I've built a noob-ish music player (currently loaded with only 2 short songs), that is controlled via a Remote Controller. The project, as a circuit is complete, but I'm still trying to figure out how to make the code even better and tweek it a little bit. I'll explain that later.
The only puprose for me making this simple project, is to make myself better at using the Arduino board and code and to say that I've made something that I find a little cool :)
Breaking The CodeThe libraries I've included:
#include <IRremote.h>
#include <LiquidCrystal.h>
Pin Initialization
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int speakerPin = 9;
int RECV_PIN = 13;
Defining different notes
#define cL 129
#define cLS 139
#define dL 146
#define dLS 156
#define eL 163
#define fL 173
#define fLS 185
#define gL 194
#define gLS 207
#define aL 219
#define aLS 228
#define bL 232
#define c 261
#define cS 277
#define d 294
#define dS 311
#define e 329
#define f 349
#define fS 370
#define g 391
#define gS 415
#define a 440
#define aS 455
#define b 466
#define cH 523
#define cHS 554
#define dH 587
#define dHS 622
#define eH 659
#define fH 698
#define fHS 740
#define gH 784
#define gHS 830
#define aH 880
#define aHS 910
#define bH 933
Buzzer Code
void beep (int speakerPin, int freqHz, long timeMs)
{
double timeDelay = (double)(1000000/freqHz);
double timeLoop = (double)((timeMs*1000)/(timeDelay*2));
for(int i = 0; i < timeLoop; i++)
{
digitalWrite(speakerPin, HIGH);
delayMicroseconds(timeDelay);
digitalWrite(speakerPin, LOW);
delayMicroseconds(timeDelay);
}
delay(20);
}
Songs
void Smoke()
{
beep(speakerPin, cH, 500);
beep(speakerPin, dHS, 500);
beep(speakerPin, fH, 500);
delay(250);
beep(speakerPin, cH, 500);
beep(speakerPin, dHS, 500);
beep(speakerPin, fHS, 250);
beep(speakerPin, fH, 550);
delay(350);
beep(speakerPin, cH, 500);
beep(speakerPin, dHS, 500);
beep(speakerPin, fH, 500);
delay(250);
beep(speakerPin, dHS, 500);
beep(speakerPin, cH, 1500);
delay(250);
}
void Jingle()
{
beep(speakerPin, e, 300);
beep(speakerPin, e, 300);
beep(speakerPin, e, 500);
delay(250);
beep(speakerPin, e, 300);
beep(speakerPin, e, 300);
beep(speakerPin, e, 500);
delay(350);
beep(speakerPin, e, 350);
beep(speakerPin, g, 350);
beep(speakerPin, c, 350);
beep(speakerPin, d, 350);
beep(speakerPin, e, 1000);
delay(250);
beep(speakerPin, f, 350);
beep(speakerPin, f, 350);
beep(speakerPin, f, 350);
beep(speakerPin, f, 300);
beep(speakerPin, f, 300);
beep(speakerPin, e, 320);
beep(speakerPin, e, 320);
beep(speakerPin, e, 150);
beep(speakerPin, e, 150);
beep(speakerPin, e, 150);
beep(speakerPin, d, 340);
beep(speakerPin, d, 340);
beep(speakerPin, e, 440);
beep(speakerPin, d, 540);
beep(speakerPin, g, 440);
delay(2000);
}
Printing the loading message
void setup()
{
lcd.begin(16,2);
irrecv.enableIRIn();
pinMode(speakerPin,OUTPUT);
lcd.print("Mike Player");
lcd.setCursor(0,1);
lcd.print("Loading.");
delay(1000);
lcd.print(".");
delay(1000);
lcd.print(".");
delay(1000);
lcd.print(".");
delay(1000);
lcd.print(".");
delay(1000);
lcd.clear();
lcd.print("Press Play");
}
And the short menu I've made (needs improvement)
void loop()
{
if (irrecv.decode(&results))
{
lcd.clear();
lcd.print("Select Song");
lcd.setCursor(0,1);
lcd.print("+:Song List");
if (results.value==0xA3C8EDDB) //+
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Smoke On The Water: 1 Jingle Bells: 2");
for (int positionCounter = 0; positionCounter < 64; positionCounter++)
{
lcd.scrollDisplayLeft();
delay(300);
}
}
if (results.value == 0x9716BE3F) //1
{
Smoke();
}
if (results.value == 0x3D9AE3F7) //2
{
Jingle();
}
irrecv.resume();
}
}
ResultConclusionI'm really satisfied with what I've done here, although this projects needs a lot of improvements. Criticize freely! Any ideas are really appreciated! Thank you for your time!
CreditsFor Smoke On The Water song: YouTube member: AndruxMX
Comments