Showing
5 changed files
with
135 additions
and
79 deletions
arduino/arduino.ino
deleted
100644 → 0
1 | -int actu = 6; | ||
2 | - | ||
3 | - | ||
4 | -const int xInput = A0; | ||
5 | -const int yInput = A1; | ||
6 | -const int zInput = A2; | ||
7 | -// initialize minimum and maximum Raw Ranges for each axis | ||
8 | -int RawMin = 0; | ||
9 | -int RawMax = 1023; | ||
10 | -int temp_x = 0; | ||
11 | -int temp_y = 0; | ||
12 | -int temp_z = 0; | ||
13 | - | ||
14 | -// Take multiple samples to reduce noise | ||
15 | -const int sampleSize = 10; | ||
16 | - | ||
17 | -void setup() | ||
18 | -{ | ||
19 | - pinMode(actu,OUTPUT); | ||
20 | - analogReference(EXTERNAL); | ||
21 | - Serial.begin(115200); | ||
22 | -} | ||
23 | - | ||
24 | -void loop() | ||
25 | -{ | ||
26 | - //Read raw values | ||
27 | - int xRaw = ReadAxis(xInput)-temp_x; | ||
28 | - int yRaw = ReadAxis(yInput)-temp_y; | ||
29 | - int zRaw = ReadAxis(zInput)-temp_z; | ||
30 | - int result = (abs(xRaw) +abs(yRaw) + abs(zRaw))/3; | ||
31 | - temp_x = ReadAxis(xInput); | ||
32 | - temp_y = ReadAxis(yInput); | ||
33 | - temp_z = ReadAxis(zInput); | ||
34 | - | ||
35 | - // Convert raw values to 'milli-Gs" | ||
36 | - long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000); | ||
37 | - long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000); | ||
38 | - long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000); | ||
39 | - | ||
40 | - // re-scale to fractional Gs | ||
41 | - float xAccel = xScaled / 1000.0; | ||
42 | - float yAccel = yScaled / 1000.0; | ||
43 | - float zAccel = zScaled / 1000.0; | ||
44 | - | ||
45 | - Serial.print("X, Y, Z :: "); | ||
46 | - Serial.print(xRaw); | ||
47 | - Serial.print(", "); | ||
48 | - Serial.print(yRaw); | ||
49 | - Serial.print(", "); | ||
50 | - Serial.print(zRaw); | ||
51 | - Serial.print(" :: "); | ||
52 | - Serial.print(xAccel,0); | ||
53 | - Serial.print("G, "); | ||
54 | - Serial.print(yAccel,0); | ||
55 | - Serial.print("G, "); | ||
56 | - Serial.print(zAccel,0); | ||
57 | - Serial.print("G"); | ||
58 | - Serial.print(" :: "); | ||
59 | - Serial.println(result); | ||
60 | - if (result < 0){ | ||
61 | - result = 0 ; | ||
62 | - | ||
63 | - } | ||
64 | - analogWrite(actu,result-3); | ||
65 | - delay(50); | ||
66 | -} | ||
67 | - | ||
68 | -// Take samples and return the average | ||
69 | -int ReadAxis(int axisPin) | ||
70 | -{ | ||
71 | - long reading = 0; | ||
72 | - analogRead(axisPin); | ||
73 | - delay(1); | ||
74 | - for (int i = 0; i < sampleSize; i++) | ||
75 | - { | ||
76 | - reading += analogRead(axisPin); | ||
77 | - } | ||
78 | - return reading/sampleSize; | ||
79 | -} |
arduino/matlab/WriteanAudioFileExample.m
0 → 100644
1 | +%% Write an Audio File | ||
2 | +% Create a WAVE file from the example file |handel.mat|, and read the file | ||
3 | +% back into MATLAB(R). | ||
4 | + | ||
5 | +%% | ||
6 | +% Write a WAVE (|.wav|) file in the current folder. | ||
7 | +load ('handel.mat') | ||
8 | +filename = 'test.wav'; | ||
9 | +audiowrite(filename,cc/3000,Fs); | ||
10 | +clear cc Fs | ||
11 | + | ||
12 | +%% | ||
13 | +% Read the data back into MATLAB using |audioread|. | ||
14 | +[cc,Fs] = audioread(filename); | ||
15 | + | ||
16 | +%% | ||
17 | +% Listen to the audio. | ||
18 | +sound(cc,Fs); | ||
19 | + | ||
20 | + | ||
21 | + | ||
22 | +%% | ||
23 | +% Copyright 2012 The MathWorks, Inc. | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
arduino/matlab/handel.mat
0 → 100644
No preview for this file type
arduino/recorder/recorder.ino
0 → 100644
1 | +#include <SD.h> | ||
2 | +#include <SPI.h> | ||
3 | + | ||
4 | +const int xInput = A1; | ||
5 | +const int yInput = A2; | ||
6 | +const int zInput = A3; | ||
7 | +int setUpTime =0; | ||
8 | +File logfile; | ||
9 | + | ||
10 | +void setup() { | ||
11 | + Serial.begin(115200); | ||
12 | + delay(1000); | ||
13 | + if (!SD.begin(4)) | ||
14 | + { | ||
15 | + Serial.println("No SD card detected. Insert SD Card"); // No card available? Let us know. | ||
16 | + while(1){ | ||
17 | + } | ||
18 | + } | ||
19 | + else{ | ||
20 | + logfile = SD.open("data.txt", O_WRITE | O_TRUNC); | ||
21 | + | ||
22 | + } | ||
23 | + setUpTime = millis(); | ||
24 | +} | ||
25 | + | ||
26 | +void loop() { | ||
27 | + int xRaw = analogRead(xInput); | ||
28 | + int yRaw = analogRead(yInput); | ||
29 | + int zRaw = analogRead(zInput); | ||
30 | + int sum = (abs(xRaw) +abs(yRaw) + abs(zRaw)); | ||
31 | + logfile.println(sum); | ||
32 | + Serial.println(sum); | ||
33 | + delayMicroseconds(805); | ||
34 | + //analogWrite(DAC1, sum); | ||
35 | + if(millis()>10000 + setUpTime){ | ||
36 | + Serial.println("Recording end"); | ||
37 | + logfile.close(); | ||
38 | + while(1){} | ||
39 | + } | ||
40 | +} |
arduino/renderer/renderer.ino
0 → 100644
1 | +/* | ||
2 | + Simple Audio Player | ||
3 | + | ||
4 | + Demonstrates the use of the Audio library for the Arduino Due | ||
5 | + | ||
6 | + Hardware required : | ||
7 | + * Arduino shield with a SD card on CS4 | ||
8 | + * A sound file named "test.wav" in the root directory of the SD card | ||
9 | + * An audio amplifier to connect to the DAC0 and ground | ||
10 | + * A speaker to connect to the audio amplifier | ||
11 | + | ||
12 | + Original by Massimo Banzi September 20, 2012 | ||
13 | + Modified by Scott Fitzgerald October 19, 2012 | ||
14 | + Modified by Arturo Guadalupi December 18, 2015 | ||
15 | + | ||
16 | + This example code is in the public domain | ||
17 | + | ||
18 | + http://www.arduino.cc/en/Tutorial/SimpleAudioPlayer | ||
19 | + | ||
20 | +*/ | ||
21 | + | ||
22 | +#include <SD.h> | ||
23 | +#include <SPI.h> | ||
24 | +#include <Audio.h> | ||
25 | + | ||
26 | +void setup() { | ||
27 | + // debug output at 9600 baud | ||
28 | + Serial.begin(115200); | ||
29 | + | ||
30 | + // setup SD-card | ||
31 | + Serial.print("Initializing SD card..."); | ||
32 | + if (!SD.begin(4)) { | ||
33 | + Serial.println(" failed!"); | ||
34 | + while(true); | ||
35 | + } | ||
36 | + Serial.println(" done."); | ||
37 | + // hi-speed SPI transfers | ||
38 | + | ||
39 | + // 44100kHz stereo => 88200 sample rate | ||
40 | + // 100 mSec of prebuffering. | ||
41 | + Audio.begin(1000, 100); | ||
42 | +} | ||
43 | + | ||
44 | +void loop() { | ||
45 | + // open wave file from sdcard | ||
46 | + File myFile = SD.open("test.wav"); | ||
47 | + if (!myFile) { | ||
48 | + // if the file didn't open, print an error and stop | ||
49 | + Serial.println("error opening test.wav"); | ||
50 | + while (true); | ||
51 | + } | ||
52 | + | ||
53 | + const int S = 1024; // Number of samples to read in block | ||
54 | + short buffer[S]; | ||
55 | + | ||
56 | + Serial.print("Playing"); | ||
57 | + // until the file is not finished | ||
58 | + while (myFile.available()) { | ||
59 | + // read from the file into buffer | ||
60 | + myFile.read(buffer, sizeof(buffer)); | ||
61 | + | ||
62 | + // Prepare samples | ||
63 | + int volume = 7000; | ||
64 | + Audio.prepare(buffer, S, volume); | ||
65 | + // Feed samples to audio | ||
66 | + Audio.write(buffer, S); | ||
67 | + } | ||
68 | + myFile.close(); | ||
69 | + | ||
70 | + Serial.println("End of file. Thank you for listening!"); | ||
71 | + while (true) ; | ||
72 | +} |
-
Please register or login to post a comment