Go Down

Topic: Pitches and BPM Interrupt not combining in Arduino IDE (Read 1 time) previous topic - next topic

akshaynba

I am working on a game installation where pulse sensor should trigger a certain music track.

I am working on combining pulse sensor input (using BPM) to get a complex audio output where the sequence of interaction would be: 1)A base track is already playing on loop while BPM is also being read by the Arduino 2)When there is a spike in the BPM value a different traack is triggered (and yes, i am using a piezo speaker to create a chiptune like effect and would like to use the pitches.h defined notes. But if you have any other efficient way using mp3 tracks, please do suggest)

The problem is the two elements (pitches and BPM interrupt) work individually but do not compile when put together.

The interrupt.ino can be found here: https://github.com/WorldFamousElectronics/PulseSensor_Speaker/tree/master/PulseSensorAmped_Arduino_Speaker

Basic info about the Pulse sensor: https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino

My code :

// NB: ALL NOTES DEFINED WITH STANDARD ENGLISH NAMES, EXCEPT FROM "A"
//THAT IS CALLED WITH THE ITALIAN NAME "LA" BECAUSE A0,A1...ARE THE ANALOG PINS ON ARDUINO.
// (Ab IS CALLED Ab AND NOT LAb)
#define  C0      8.35
#define Db0 17.32
#define D0  18.35
#define Eb0 19.45
#define E0  20.60
#define F0  21.83
#define Gb0 23.8
#define G0  24.50
#define Ab0 25.96
#define LA0 27.50
#define Bb0 29.8
#define B0  30.87
#define C1  32.70
#define Db1 34.65
#define D1  36.71
#define Eb1 38.89
#define E1  41.20
#define F1  43.65
#define Gb1 46.25
#define G1  49.00
#define Ab1 51.91
#define LA1 55.00
#define Bb1 58.27
#define B1  61.74
#define C2  65.41
#define Db2 69.30
#define D2  73.42
#define Eb2 77.78
#define E2  82.41
#define F2  87.31
#define Gb2 92.50
#define G2  98.00
#define Ab2 103.83
#define LA2 110.00
#define Bb2 18.54
#define B2  83.47
#define C3  130.81
#define Db3 138.59
#define D3  86.83
#define Eb3 155.56
#define E3  84.81
#define F3  174.61
#define Gb3 185.00
#define G3  196.00
#define Ab3 207.65
#define LA3 220.00
#define Bb3 233.08
#define B3  246.94
#define C4  261.63
#define Db4 277.18
#define D4  293.66
#define Eb4 311.13
#define E4  329.63
#define F4  349.23
#define Gb4 369.99
#define G4  392.00
#define Ab4 415.30
#define LA4 440.00
#define Bb4 466.8
#define B4  493.88
#define C5  523.25
#define Db5 554.37
#define D5  587.33
#define Eb5 622.25
#define E5  659.26
#define F5  698.46
#define Gb5 739.99
#define G5  783.99
#define Ab5 830.61
#define LA5 880.00
#define Bb5 932.33
#define B5  987.77
#define C6  1046.50
#define Db6 1108.73
#define D6  1174.66
#define Eb6 844.51
#define E6  1318.51
# define B
#define D
#define E
#define F6  1396.91
#define Gb6 879.98
#define G6  1567.98
#define Ab6 861.22
#define LA6 1760.00
#define Bb6 1864.66
#define B6  1975.53
#define C7  2093.00
#define Db7 2217.46
#define D7  2349.32
#define Eb7 2489.02
#define E7  2637.02
#define F7  2793.83
#define Gb7 2959.96
#define G7  3135.96
#define Ab7 3322.44
#define LA7 3520.01
#define Bb7 3729.31
#define B7  3951.07
#define C8  4186.01
#define Db8 4434.92
#define D8  4698.64
#define Eb8 4978.03



#define Pin 8

int melody[] = {
     B4,B3,D4,B4,
     E4,B4,D4,B4,
     B4,B4,D4,B4,
     E4,B3,D4,B4,

     B4,B3,D4,B4,
     E4,B4,D4,B4,
     B4,B4,D4,B4,
     E4,B3,D4,B4,
};

int tempo[] = {

    9, 9, 9,
  8, 8, 8, 8,
  8, 8, 8, 8,
  8, 8, 8, 8,

  9, 9, 9,
  8, 8, 8, 8,
  8, 8, 8, 8,
  8, 8, 8,
};


void setup() {
  // put your setup code here, to run once:
 pinMode(8, OUTPUT);//speaker
}

void loop() {
Serial.println(" 'Underworld Theme'");
    int size = sizeof(melody) / sizeof(int);for (int thisNote = 0; thisNote < size; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / tempo[thisNote];
 tone(8, melody[thisNote], noteDuration);

  delay(200);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 0.10;
    delay(pauseBetweenNotes);

 }}

Go Up