hey people,
its my first post.
i'm trying to make the piano from the starter kit (unsuccesfuly...)
could someone pls help me?
could someone pls help me?
Not without more information. There are dozens of starter kits, to which one do you refer?
If you are having trouble with the code, post the code and tell us what it is supposed to do and how that differs from what the code actually does.
Please read the "how to use the forum-please read" stickies to see what we need to know in order to help you and how to post code properly. See #7 & 11 especially.
int notes[] = {262,294,330,349};
void setup() {
Serial.begin(9600);
}
void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);
if(keyVal == 1023){
}
else if(keyVal >= 990 && keyVal<= 1010){
tone(8, notes[1]);
}
{else if(keyVal >= 505 && keyVal <=515
tone(8, notes[2]);
}
{else if(keyVal >= 5 && keyVal <=10
tone(8, notes[3]);
}
else{
noTone(8);
}
}
Looks like you need to copy the code more carefully.
groundFungus:
If you are having trouble with the code, post the code and tell us what it is supposed to do and how that differs from what the code actually does.
Or if you are getting a compile error then post the error message.
Thank you for using code tags.
You have misplaced and missing curly brackets and missing parenthesis.
int notes[] = {262,294,330,349};
void setup() {
Serial.begin(9600);
}
void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);
if(keyVal == 1023)
{
}
else if(keyVal >= 990 && keyVal<= 1010)
{
tone(8, notes[1]);
}
{ // this { is misplaced
else if(keyVal >= 505 && keyVal <=515 // you are missing a closing parenthesis
// you are missing an opening {
tone(8, notes[2]);
}
{ // this { is misplaced
else if(keyVal >= 5 && keyVal <=10 // you are missing a closing parenthesis
// you are missing an opening {
tone(8, notes[3]);
}
else
{
noTone(8);
}
}
If you put every { and } on their own line it is easier to see missing and misplaced { and }.
If you use the auto format tool (ctrl-t or Tools, Auto Format), often misplaced and missing {, }, ( and ) will be more apparent.
Your code fixed to compile and formatted:
int notes[] = {262, 294, 330, 349};
void setup()
{
Serial.begin(9600);
}
void loop()
{
int keyVal = analogRead(A0);
Serial.println(keyVal);
if (keyVal == 1023)
{
}
else if (keyVal >= 990 && keyVal <= 1010)
{
tone(8, notes[1]);
}
else if (keyVal >= 505 && keyVal <= 515)
{
tone(8, notes[2]);
}
else if (keyVal >= 5 && keyVal <= 10)
{
tone(8, notes[3]);
}
else
{
noTone(8);
}
}