Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Programming Arduino Uno using a 2 dimentional array issue

Status
Not open for further replies.
Try changing from loop down to,
Code:
void loop() {
  int potVal = map(analogRead(A2), 0, 1024, 0, 3);
  for (int i = 0; i < numberOfButtons; i++) {
    checkButton(potVal,i);
  }
}

void checkButton(int scaleNum,int buttonNum)
{
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin[buttonNum]);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    digitalWrite(ledPin[buttonNum], HIGH);
    tone(speaker, notes[scaleNum][buttonNum]);                 // play the note
    delay(100);                       // wait for 1/10th of a second
  } else {
    digitalWrite(ledPin[buttonNum], LOW);
    noTone(speaker);                  // stop playing the note
  }
}
Note, got to go out now (take grandkids presents) but will check back later.

Mike.
Edit, above been edited.
 
Last edited:
Just to stop any confusion on my part and due to my lack of skills in programming, when you say i & j I can still use "scales & columns" in their place, no?
 
More than a star!! Your a friggin constellation of stars!! Yes it's working as hoped Mike. Sincerely, a big thanks for that!!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top