//NIME Scaffolding
//Programmed by Andrew Freitas
#include <Servo.h>
#include <Adafruit_Circuit_Playground.h>
#include <Adafruit_CircuitPlayground.h>
//Variables
Servo myservo;
int servoState = 0;
int pitchAdjust = 1;
void setup(){
  //Starts CPE
  CircuitPlayground.begin(); 
  //Recognize servo from A3
  myservo.attach(A3); 
  Serial.begin(9600);
  delay(1000);
}
void loop() {
  //Toggle Drum Beat
  if (digitalRead(CPLAY_RIGHTBUTTON)){
    servoState = 1;
  } 
  //Deactivate Drum Beat
  if (digitalRead(CPLAY_LEFTBUTTON)){
    servoState = 0;
  }
  //Drum Beat
  if (servoState == 1){
    myservo.write(180);
    delay(150);
    myservo.write(0);
    delay(75);
  }
    //Potentiometer control
    pitchAdjust = analogRead (A7);
    Serial.println (pitchAdjust);
    pitchAdjust = map(pitchAdjust, 1, 1024, 1, 255);
    Serial.println (pitchAdjust);
  //Play Song: Crazy Train
  if (digitalRead(CPLAY_SLIDESWITCHPIN)) {         
    //Default values for crazy train, adds pitchAdjust to alter Pitch
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(277 + pitchAdjust, 100); //C#4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(294 + pitchAdjust, 100); //D4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(277 + pitchAdjust, 100); //C#4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(494 + pitchAdjust, 100); //B4
    CircuitPlayground.playTone(440 + pitchAdjust, 100); //A4
    CircuitPlayground.playTone(415 + pitchAdjust, 100); //G#4
    CircuitPlayground.playTone(440 + pitchAdjust, 100); //A4
    CircuitPlayground.playTone(494 + pitchAdjust, 100); //B4
    CircuitPlayground.playTone(440 + pitchAdjust, 100); //A4
    CircuitPlayground.playTone(415 + pitchAdjust, 100); //G#4
    CircuitPlayground.playTone(330 + pitchAdjust, 100); //E4
  }
}

No comments:
Post a Comment
Note: Only a member of this blog may post a comment.