subeen

레코더 렌더러 코드 업데이트

int actu = 6;
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;
// initialize minimum and maximum Raw Ranges for each axis
int RawMin = 0;
int RawMax = 1023;
int temp_x = 0;
int temp_y = 0;
int temp_z = 0;
// Take multiple samples to reduce noise
const int sampleSize = 10;
void setup()
{
pinMode(actu,OUTPUT);
analogReference(EXTERNAL);
Serial.begin(115200);
}
void loop()
{
//Read raw values
int xRaw = ReadAxis(xInput)-temp_x;
int yRaw = ReadAxis(yInput)-temp_y;
int zRaw = ReadAxis(zInput)-temp_z;
int result = (abs(xRaw) +abs(yRaw) + abs(zRaw))/3;
temp_x = ReadAxis(xInput);
temp_y = ReadAxis(yInput);
temp_z = ReadAxis(zInput);
// Convert raw values to 'milli-Gs"
long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);
// re-scale to fractional Gs
float xAccel = xScaled / 1000.0;
float yAccel = yScaled / 1000.0;
float zAccel = zScaled / 1000.0;
Serial.print("X, Y, Z :: ");
Serial.print(xRaw);
Serial.print(", ");
Serial.print(yRaw);
Serial.print(", ");
Serial.print(zRaw);
Serial.print(" :: ");
Serial.print(xAccel,0);
Serial.print("G, ");
Serial.print(yAccel,0);
Serial.print("G, ");
Serial.print(zAccel,0);
Serial.print("G");
Serial.print(" :: ");
Serial.println(result);
if (result < 0){
result = 0 ;
}
analogWrite(actu,result-3);
delay(50);
}
// Take samples and return the average
int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
delay(1);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
}
%% Write an Audio File
% Create a WAVE file from the example file |handel.mat|, and read the file
% back into MATLAB(R).
%%
% Write a WAVE (|.wav|) file in the current folder.
load ('handel.mat')
filename = 'test.wav';
audiowrite(filename,cc/3000,Fs);
clear cc Fs
%%
% Read the data back into MATLAB using |audioread|.
[cc,Fs] = audioread(filename);
%%
% Listen to the audio.
sound(cc,Fs);
%%
% Copyright 2012 The MathWorks, Inc.
\ No newline at end of file
No preview for this file type
#include <SD.h>
#include <SPI.h>
const int xInput = A1;
const int yInput = A2;
const int zInput = A3;
int setUpTime =0;
File logfile;
void setup() {
Serial.begin(115200);
delay(1000);
if (!SD.begin(4))
{
Serial.println("No SD card detected. Insert SD Card"); // No card available? Let us know.
while(1){
}
}
else{
logfile = SD.open("data.txt", O_WRITE | O_TRUNC);
}
setUpTime = millis();
}
void loop() {
int xRaw = analogRead(xInput);
int yRaw = analogRead(yInput);
int zRaw = analogRead(zInput);
int sum = (abs(xRaw) +abs(yRaw) + abs(zRaw));
logfile.println(sum);
Serial.println(sum);
delayMicroseconds(805);
//analogWrite(DAC1, sum);
if(millis()>10000 + setUpTime){
Serial.println("Recording end");
logfile.close();
while(1){}
}
}
/*
Simple Audio Player
Demonstrates the use of the Audio library for the Arduino Due
Hardware required :
* Arduino shield with a SD card on CS4
* A sound file named "test.wav" in the root directory of the SD card
* An audio amplifier to connect to the DAC0 and ground
* A speaker to connect to the audio amplifier
Original by Massimo Banzi September 20, 2012
Modified by Scott Fitzgerald October 19, 2012
Modified by Arturo Guadalupi December 18, 2015
This example code is in the public domain
http://www.arduino.cc/en/Tutorial/SimpleAudioPlayer
*/
#include <SD.h>
#include <SPI.h>
#include <Audio.h>
void setup() {
// debug output at 9600 baud
Serial.begin(115200);
// setup SD-card
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println(" failed!");
while(true);
}
Serial.println(" done.");
// hi-speed SPI transfers
// 44100kHz stereo => 88200 sample rate
// 100 mSec of prebuffering.
Audio.begin(1000, 100);
}
void loop() {
// open wave file from sdcard
File myFile = SD.open("test.wav");
if (!myFile) {
// if the file didn't open, print an error and stop
Serial.println("error opening test.wav");
while (true);
}
const int S = 1024; // Number of samples to read in block
short buffer[S];
Serial.print("Playing");
// until the file is not finished
while (myFile.available()) {
// read from the file into buffer
myFile.read(buffer, sizeof(buffer));
// Prepare samples
int volume = 7000;
Audio.prepare(buffer, S, volume);
// Feed samples to audio
Audio.write(buffer, S);
}
myFile.close();
Serial.println("End of file. Thank you for listening!");
while (true) ;
}