Project in progress
P Comp Week 4

P Comp Week 4

  • 2 views
  • 0 comments
  • 0 respects

About this project

Code

P Comp week 4 old Town RoadArduino
#include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_E4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_A3, NOTE_A3, NOTE_E4, NOTE_D4, NOTE_C4,0,NOTE_A3,NOTE_G3,NOTE_D4, NOTE_D4, NOTE_E4, NOTE_C4, NOTE_A3, NOTE_A3,
  
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  8, 8, 4, 4, 4, 8, 8, 8, 4,8,8,8,8,2,4,4,8,4,4
};
void setup() {
 Serial.begin(9600);

}

 
 void loop() {

   
   // get a sensor reading:
   int sensorReading = analogRead(A0);
   int frequency= map(sensorReading, 0, 1023, 100,880);
   if(sensorReading>600){
       // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 19; 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 / noteDurations[thisNote];
    tone(9, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(9);
    
    Serial.println("pressed");
    }
   }
    else {
      Serial.println("not pressed");
      }
   


 }

Comments

Similar projects you might like

Day of the Week calculator

Project tutorial by Eric Sitler

  • 2,632 views
  • 0 comments
  • 3 respects

Bluetooth Controlled Car

Project in progress by Saman Fernando

  • 219,855 views
  • 128 comments
  • 162 respects

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 128,072 views
  • 32 comments
  • 116 respects

TB6600 Stepper Motor driver Tester

Project in progress by ashleyblack

  • 37,214 views
  • 27 comments
  • 36 respects

Arduino Frequency Counter with 16×2 LCD Display

Project in progress by jasir

  • 28,015 views
  • 8 comments
  • 20 respects

Smart Wardrobe

Project in progress by Tan See Youu

  • 23,470 views
  • 8 comments
  • 56 respects
Add projectSign up / Login