20 March 2022

NIME team 15

 

by: Daniel Velasco and Kyle Spence

For our project we used a simple cardboard box for the enclosure of the Circuit Playground express. We used simple alligator clips and the electronics breadboard and connected the A4 pin to the servo and the A3 pin to the potentiometer. We wanted to have a more or less self contained instrument that plays a short song when the D6 button is pressed, and if the D4 button is pressed it plays a short tone through the servo, we made a song using the note designations, gave each one a particular length and then we made a float song with ranging values, 392 being a repeating value. In our int percentage, our data is 0, 1023, 0, 100, for the Potentiometer pin. We made sure that there weren’t any negative feedbacks so we followed the video and made the pinmode 13 and the two input pulldowns 4 and 5. Overall we tried to keep the code short and concise because we wanted something that can be easily transferred or understood. We also wanted to the timer limit +15 in the if(mills) lines, at the beginning of the project we were playing around with notes and playtones, we settled on 600 and 100. So overall a very simple set up.










                                Code- 
#include <Servo.h>
#include<Adafruit_CircuitPlayground.h>
#include<Adafruit_Circuit_Playground.h>
#define POTENTIOMETER_PIN A1
Servo myServo;
int pos = 0;
int inc = 1;
int timer = 0;
// A, B, C, D,
// 440, 493, 88 , 523.25, 587,33, 659.25, 698.46, 783.99, 880 
float note[] = {440, 493.88 , 523.25, 587.33, 659.25, 698.46, 783.99, 880};
float lenghts[] = {200,200,300,200,200,200,500};
float song[] = {400, 392,349.23, 392,500,600,300};
int numNotes = sizeof(song)/sizeof(float);


void setup() {
  
  // put your setup code here, to run once:
CircuitPlayground.begin();
Serial.begin(9600);
//delay(1000);
myServo.attach(3);//A3
pinMode(13, OUTPUT);
pinMode(4 , INPUT_PULLDOWN);
pinMode(5 , INPUT_PULLDOWN);
}



void loop() {
  //POTENTIOMETER
  Serial.println(analogRead(POTENTIOMETER_PIN));
  delay(100);
int data = analogRead(POTENTIOMETER_PIN);
  int percentage = map(data, 0, 1023, 0, 100);
  
  if(millis() > timer + 15){
  if(pos == 0) inc = 1;
  if(pos == 180) inc = -1;
  myServo.write(pos);
  pos += inc;
  timer = millis();
  }
  digitalWrite(13, digitalRead(4)); //d13 light
  // put your main code here, to run repeatedly:
  //play tone with D4 button
if(millis() > timer + 15){
  if(pos == 0) inc = 1;
  if(pos == 180) inc = -1;
  myServo.write(pos);
  pos += inc;
  timer = millis();
 if(digitalRead(4))CircuitPlayground.playTone(600,100, false);
 timer = millis();
 if(digitalRead(5))
 {
for(int i = 0; i < numNotes; i++){
Serial.println(note[i]);
CircuitPlayground.playTone(song[i],lenghts[i]);
     }
      digitalWrite(13, digitalRead(4));
    }
 }
}











No comments:

Post a Comment

Note: Only a member of this blog may post a comment.