I am working on a design project for school and need some help with writing code for the Arduino. I am trying to use the Arduino to do the following:
Record sound data.
Threshold that sound data.
Detect when sound breaks threshold, and output a signal to a speaker to signify threshold being broken.
After the first time the signal breaks threshold, check every second and a half to see if a signal again broke threshold. If it did, just continue to check every second and a half. If it did not, then it should again output a signal to the speaker to signify threshold being broken.
I have written a working program in MATLAB, but am completely new to the Arduino board, and have never programmed in anything besides MATLAB, and need some help! This is the MATLAB code I wrote:
fs = 1000; %Sampling Rate
s = 3; %Time of data aquisition in seconds
%%%%%Phase 2: Re-starting Acquisition. Waiting for first signal that breaks
%%%%%Phase 3: predicting last beat
The code and device works perfectly in MATLAB, and I think it should work using the Arduino as well. Here is my crude Arduino code for steps 1 -3 above, which is not working, but I’m not sure why. Help is greatly appreciated! Thanks all!
int analogPin = 3; // AI pin connected to analog pin 3
int outPin = 9; // outside leads to ground and +5V
int data; // variable to store the value read
Serial.begin(9600); // setup serial
for (int i=1; i <= 3000; 1)
val = analogRead(analogPin); // read the input pin
delayMicroseconds(900);} // sample at about 1000 hz
val = analogRead(analogPin)