Using the Energia software, as well as the Education BoosterPack MKII, what is the program/code that combines the input function of the joystick, using either the X or Y axis reading, and uses it to produce a tone on the buzzer, such that the buzzer tone varies in pitch when you move the joystick along whichever axis you have chosen? For example, if you have chosen the X axis to read, you should hear a low tone when the joystick is moved to the left, and should progress steadily to a higher tone when you move the joystick to the right.
#define X axis #define Y axis const int joystick Sel = 5; const int joystick X = 2; const int joystick Y = 26; int joystickSelState = 0; int joystickXState, joystickYState ; int buzzerPin = 19; int melody[] = { x axis ,y axis}; int noteDurations[] = { 4,2}; { void setup() { pinMode(buzzerPin, OUTPUT); } }
void loop()
{
for (int thisNote = 0; thisNote < 26; thisNote++)
{
int noteDuration = 1000/noteDurations[thisNote];
tone(buzzerPin, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration + 50;
delay(pauseBetweenNotes);
noTone(buzzerPin);
}
}
Get Answers For Free
Most questions answered within 1 hours.