This is my first Arduino project and I’m pretty terrible at this. I’ve created a box with 8 photocells in it, and I want each one to play a different sound when your hand is in front of it (the C major scale, specifically).
I built the wave shield and the sounds are playing fine when playing them in a basic sequence. But I am trying to write the code to make it responsive now and I cannot get it to work! I could be entirely wrong in how I wrote this but being that I can’t find any tutorials doing exactly what I am, I parsed bits of different tutorials I found together. And I’m not getting any results lol. I need this done hopefully by tonight so ANY AND ALL HELP IS MUCH APPRECIATED!!!
#include <FatReader.cpp>
#include <FatReader.h>
#include <SdReader.cpp>
#include <SdReader.h>
#include "WaveHC.h"
#include <WaveUtil.cpp>
#include "WaveUtil.h"
int sensorPinC4 = 0;
int sensorPinD4 = 1;
int sensorPinE4 = 6;
int sensorPinF4 = 7;
int sensorPinG4 = 8;
int sensorPinA4 = 9;
int sensorPinB4 = 11;
int sensorPinC5 = 12;
// select the input pin for the photocell
int sensorValueC4 = 0; // variable to store the value coming from the photocell
int sensorValueD4 = 0;
int sensorValueE4 = 0;
int sensorValueF4 = 0;
int sensorValueG4 = 0;
int sensorValueA4 = 0;
int sensorValueB4 = 0;
int sensorValueC5 = 0;
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play
WaveHC wave;
void setup() {
Serial.begin(9600); //Set baud rate to 9600 on the Arduino
}
void playfile(char *name) {
wave.play();
}
void loop() {
// read the value from the sensor
sensorValueC4 = digitalRead(sensorPinC4); //get the voltage value from input pin
Serial.println(sensorValueC4); //print the value to Serial monitor
delay(2000); //delay for 2 seconds
if (sensorValueC4 < 300) {
playfile("C4NOTE.WAV");
} //play sound
sensorValueD4 = digitalRead(sensorPinD4);
Serial.println(sensorValueD4);
delay(2000);
if (sensorValueD4 < 300) {
playfile("D4NOTE.WAV");
}
sensorValueE4 = digitalRead(sensorPinE4);
Serial.println(sensorValueE4);
delay(2000);
if (sensorValueE4 < 300) {
playfile("E4NOTE.WAV");
}
sensorValueF4 = digitalRead(sensorPinF4);
Serial.println(sensorValueF4);
delay(2000);
if (sensorValueF4 < 300) {
playfile("F4NOTE.WAV");
}
sensorValueG4 = digitalRead(sensorPinG4);
Serial.println(sensorValueG4);
delay(2000);
if (sensorValueG4 < 300) {
playfile("G4NOTE.WAV");
}
sensorValueA4 = digitalRead(sensorPinA4);
Serial.println(sensorValueA4);
delay(2000);
if (sensorValueA4 < 300) {
playfile("A4NOTE.WAV");
}
sensorValueB4 = digitalRead(sensorPinB4);
Serial.println(sensorValueB4);
delay(2000);
if (sensorValueB4 < 300) {
playfile("B4NOTE.wav");
}
sensorValueC5 = digitalRead(sensorPinC5);
Serial.println(sensorValueC5);
delay(2000);
if (sensorValueC5 < 300) {
playfile("C5NOTE.WAV");
}
}