Question
I have to write a simple program (The Piano - Using buttons and speaker, create a program that plays different notes when different buttons are
I have to write a simple program (The Piano - Using buttons and speaker, create a program that plays different notes when different buttons are pressed.)
Order of Flow Piano
First Decision Level Play Note 1 when Button 1 is pressed
Second Decision Level Play Note 2 when Button 2 is pressed
Third Decision Level Play Note 3 when Button 3 is pressed
That is the code
////INCLUDE STATEMENTS // Including the libraries with the functions we need for this program #include
////MAIN - Every C++ program beings with main() function int main() {
//TODO - Define variables you might need throughout the code here //Suggestions? Variables to store note frequencies, pin output values
//Required at beginning of each lab file - initialize Arduino and other hardware. initLab();
//Required by Arduino - main() function must have this WHILE loop //Use it to keep the program running while (true == true) - ie forever! while ( true ) {
//TODO - Implement design (flowchart) here in C++ //NOTE that you can call digitalRead() from the Arduino library to get button state //- If a button is pressed, the value returned from digitalRead() will be HIGH //- If a button is not pressed, the value returned from digitalRead() will be LOW
//Wait for 100ms before ending loop delay(100); }
//Every main() needs to return a value because its type is not void return 0; }
--------------------------------
usful functions
//General library functions
void initLab();
//LCD functions and variables
void initLCD(unsigned int r, unsigned int g, unsigned int b);
void printLCD(const String msg);
void printLCD(const float msg);
void clearLCD();
void backgroundLCD(unsigned int r, unsigned int g, unsigned int b);
//Temperature sensor-related functions and variables
const int B = 4275; // B value of the thermistor
const long R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
float calculateCelsius(int sensorValue);
void printCelsius(float c);
void printFahrenheit(float f);
void setTemperatureColour(float p);
//Rotary dial sensor functions and variables
const int ADC_REF = 5; //reference voltage of ADC is 5v
const int VCC = 5; //VCC of the grove interface
const int FULL_ANGLE = 300; //full value of the rotary angle
const int pinRotarySensor = A1; // Grove - Rotary Sensor connect to A1
//Light sensor functions and variables
const int pinLightSensor = A2; // Grove - Light Sensor connect to A2
//Speaker functions and variables
#define SPEAKER 3 //Indicates speaker will be in D3
void playNote(int f);
//LED functions and variables
#define LED_1 2 //Indicates LED_1 will be in D2
void powerLED();
//Button functions and variables
#define BUTTON_1 8 //Indicates BUTTON_1 will be in D8
#define BUTTON_2 7 //Indicates BUTTON_2 will be in D7
#define BUTTON_3 6 //Indicates BUTTON_3 will be in D6
#define BUTTON_4 5 //Indicates BUTTON_4 will be in D5
//Note that to read button values, you will need to call the Arduino library function
// int val = digitalRead(int pinNumber);
// More info: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/
//Button functions and variables
#define TILT_1 8 //Indicates TILT_1 will be in D8
#define TILT_2 7 //Indicates TILT_2 will be in D7
//Note that to read tilt sensor values, you will need to call the Arduino library function
// int val = digitalRead(int pinNumber);
// More info: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/
//Ultrasonic functions and variables
const int trigPin = 9; //Trig - white Jumper
const int echoPin = 8; //Echo - yellow Jumper
long getSonicDistance();
//LED Bar functions and variables
const int clockPin = 7; //Clock Pin for LED Bar
const int dataPin = 6; //Data Pin for LED Bar
const bool orientation = true;
void initBar();
void setBarLevel(float level);
void setBarLED(int led, float brightness);
void toggleBarLED(int led);
void setBarBits(unsigned int bits);
//Servo functions and variables
#define SERVO_1 4 //Indicates TILT_1 will be in D4
void setServoPosition(float angle);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started