Hello There, I Have started on a project, and am not sure how to do what I need.
What I need is for when somebody presses the "up" button it changes the pitch to the next pitch up, and the "down" button changes the pitch to the next pitch down, and If it reaches the last note on either side, it goes to the next pitch. EX:
F3?F#3?G3?G#3?A3?A#3?B3?C4?C#4?D4?D#4?E4?F4?F3
So when It reaches the top, it would repeat, and when it reaches the bottom, it would do the same, but loop to the top.
So far this is the code that I have, I have the pitches and frequencies, but I cannot figure out how to switch to the next pitch.
Code:
#include <LiquidCrystal.h>
#include <DFR_Key.h>
//Initialize Tones
/*
T1= F3, T2= F#3, T3= G3, T4= G#3, T5= A3, T6= A#3, T7= B3, T8= C4, T9=C#4,
T10= D4, T11= D#4, T12= E4, T13= F4.
*/
int const T1 = 175;
int const T2 = 185;
int const T3 = 196;
int const T4 = 208;
int const T5 = 220;
int const T6 = 233;
int const T7 = 247;
int const T8 = 262;
int const T9 = 277;
int const T10 = 294;
int const T11 = 311;
int const T12 = 330;
int const T13 = 349;
int currentNote = T1;
//Pin assignments for DFRobot LCD Keypad Shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//---------------------------------------------
DFR_Key keypad;
int localKey = 0;
String keyString = "";
void setup()
{
pinMode(50, OUTPUT);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Connor's Tuner");
delay(2500);
keypad.setRate(10);
}
void loop()
{
/*
keypad.getKey();
Grabs the current key.
Returns a non-zero integer corresponding to the pressed key,
OR
Returns 0 for no keys pressed,
OR
Returns -1 (sample wait) when no key is available to be sampled.
*/
localKey = keypad.getKey();
if (localKey != SAMPLE_WAIT)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Current Note:");
lcd.setCursor(0, 12);
}
if (localKey == 3)
{
currentNote = currentNote + 1;
}
}
I have no idea if how I'm doing it is right, or if it is even possible.
Thanks for any help!