Please Help!

Can’t seem to get my code to work the way I need it to. There’s tons of extra in here, and I’ll try to cut out the stuff that is not needed. My power on button with the interrupt is working fine. When I try another button in combination with the power on button, it does not function as I would like. When I toggle the second button on, the LED comes on, then when I toggle it off, it flashes on and off at different intervals. I’m new to all of this, and think that I’m likely missing something simple, however I’m relatively inexperienced in writing code.

#define BUZZER 10 // define buzzer as pin 10
#define MIN_BPM 40 // define minimum bpm value
#define MAX_BPM 180 // define maximum bpm value
#define POT A1 // define potentiometer analog pin
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include “Adafruit_LEDBackpack.h”
#include <Adafruit_NeoPixel.h>
#define PIN 13
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

const int button1Pin = 2;
const int button2Pin = 3;

const int led1Pin = 6;
const int led2Pin = 7;
const int led5Pin = 11;
const int led6Pin = 12;

int Button1State = 0;
int bpm;
Adafruit_7segment matrix = Adafruit_7segment();

void setup() {
Serial.begin(9600); // starts serial communication at 9600 bits per seconds
attachInterrupt(0, Start, FALLING); // ISR on pin 2 (INT0) when there is a falling edge

#ifndef AVR_ATtiny85
Serial.begin(9600);

pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(led4Pin, OUTPUT);
pinMode(led5Pin, OUTPUT);
pinMode(led6Pin, OUTPUT);
pinMode(BUZZER, OUTPUT); // buzer pin as output

#endif
matrix.begin(0x70); //initiates the I2C matrix. 2 pins are required (C-clock A5 and D-Data A4). 0x70
strip.begin();
strip.show();
}

void loop() {
const int Button2State = digitalRead(3);
const int Button3State = digitalRead(4);
const int Button4State = digitalRead(5);
if (Button1State == 0){
bpm = map(analogRead(POT), 0, 1023, MIN_BPM, MAX_BPM); // maps analog pot value to MIN_BPM - MAX_BPM range
matrix.print(bpm);
matrix.writeDisplay();
delay(100);
digitalWrite(led2Pin, LOW);
}
if (Button1State == 1){
powerOnMode();
}

void powerOnMode(){ // Power On, No Hit Detection

const int Button2State = digitalRead(3);

digitalWrite(led1Pin, HIGH);
tone(BUZZER, 2000); // does a “bip” for…
digitalWrite(led5Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led5Pin, LOW);
delay(54000 / bpm); // 90% of T

tone(BUZZER, 2000); // does a “bip” for…
digitalWrite(led6Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led6Pin, LOW);
delay(54000 / bpm); // 90% of T

tone(BUZZER, 2000); // does a “bip” for…
digitalWrite(led6Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led6Pin, LOW);
delay(54000 / bpm); // 90% of T

tone(BUZZER, 2000); // does a “bip” for…
digitalWrite(led6Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led6Pin, LOW);
delay(54000 / bpm); // 90% of T

if (Button2State == HIGH){
quarterNoteMode();
}

void Start(){ // ***** This is for stopping the metronome all together

Button1State = !Button1State;
delay(30);

if(Button1State == 0){
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, LOW);
digitalWrite(led4Pin, LOW);
noTone(BUZZER);
}
} // *****

void quarterNoteMode(){

const int Button2State = digitalRead(3);
digitalWrite(led2Pin, HIGH);
tone(BUZZER, 2000); // does a “bip”
digitalWrite(led5Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led5Pin, LOW);
delay(54000 / bpm); // 90% of T

tone(BUZZER, 2000); // does a “bip” for…
digitalWrite(led6Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led6Pin, LOW);
delay(54000 / bpm); // 90% of T

tone(BUZZER, 2000); // does a “bip” for…
digitalWrite(led6Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led6Pin, LOW);
delay(54000 / bpm); // 90% of T

tone(BUZZER, 2000); // does a “bip” for…
digitalWrite(led6Pin, HIGH);
delay(6000 / bpm); // 10% of T (where T is the time between two BPSs)
noTone(BUZZER); // silence for…
digitalWrite(led6Pin, LOW);
delay(54000 / bpm); // 90% of T
}

I don’t know why it won’t stay in the quarterNoteMode, it seems to cycle through both. When I have gotten it to stay in the second mode, the led2Pin toggles on and off…

Your code does something. You partially explained what it does. You want your code to do something. You DID NOT explain your expectations. How can anyone help except by playing guessing games?

You have a function called Start with a comment that it is used to stop the metronome. Huh?

You need to read the first three posts and what they link to so that you may properly post.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Did you write this code. Did you write your code in stages, then combine them, [u]but[/u] getting each stage to work before combining?

How have you got your buttons wired, I see no pinMode statements for INPUT. Yet you digitalRead pins 3,4 and 5.

Thanks.. Tom... :)

 Button1State = !Button1State;
  delay(30);
  
  if(Button1State == 0){

Why do you invert the state of the variable before testing it ? delay() does not work in ISRs because interrupts are disabled.

Hey guys, sorry about the formatting… New to this forum. Thanks for the ‘how to’ link for posting. I figured out my issue. Again, sorry for the mess of a post…

Hi, What was your issue. Please to make this thread complete, what was the solution?

Tom.... :)