day 19

LAB

#include <TimerOne.h>
#include "pitches.h"
const int BUTTON_INT = 0;
const int SPEAKER = 12;
volatile int key = NOTE_C2;
volatile int octave_multiplier = 1;
long timer = 500000;

void setup()
{
  Serial.begin(9600);
  pinMode(SPEAKER, OUTPUT);
  attachInterrupt(BUTTON_INT, changeKey, RISING);
  Timer1.initialize(timer);
  Timer1.attachInterrupt(changePitch);
}

void changeKey()
{
  octave_multiplier = 1;
  if (key == NOTE_C2)
    key = NOTE_D2;
  else if (key == NOTE_D2)
    key = NOTE_E2;
  else if (key == NOTE_E2)
    key = NOTE_F2;
  else if (key == NOTE_F2)
    key = NOTE_G2;
  else if (key == NOTE_G2)
    key = NOTE_A2;
  else if (key == NOTE_A2)
    key = NOTE_B2;
  else if (key == NOTE_B2)
    key = NOTE_C2;
    timer -= 10000;
  Timer1.initialize(timer);
   
}

void changePitch()
{
  octave_multiplier = octave_multiplier * 2;
  if (octave_multiplier > 16) octave_multiplier = 1;
  tone(SPEAKER, key*octave_multiplier);
 
}

void loop()
{
 
}

Comments

Popular posts from this blog

DAY 17

Day 21