hi im trying to attach an interrupt to this script so a button will trigger it and the code will reevaluate the value from the potentiometer thus immediately changing the tempo, all help will be greatly appreciated, im a beginner and totally in the dark here, thanks
code:
int speakerPin = 9;
int length = 128; // the number of notes
char notes[] = "cccdcecfcgcacbcCdcdddedfdgdadbdCecedefegeaebeCfcfdfefffgfafbfCgcgdgegfgggagbgCacadaeafagaaabaCbdbcbebfbgbabbbCCcCdCeCfCgCaCbCC"; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int tempo = 100;
int potPin = 2; // select the input pin for the potentiometer
int val = 0; // variable to store the value coming from the sensor
int pin = 13;
volatile int state = LOW;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };
// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names == note) {
_ playTone(tones*, duration);_
_ }_
_ }_
_}_
void setup() {
_ pinMode(speakerPin, OUTPUT);_
_}_
void loop() {
_ val = analogRead(potPin); // read the value from the sensor*_
* for (int i = 0; i < length; i++) {*
_ if (notes == ' ') {
delay(beats * val); // rest
* } else {_
playNote(notes, beats _ tempo);
* }
// pause between notes*
* delay(val / 30);
}
}*_