Hi,
I have encountered a problem I lack the direction to fix. I need a push in the right direction.
I want the record function of a seeeduino music shield to be triggered by an accelerometer via a Arduino MEGA. The problem being the record function is currently set so that you have to
Press play/stop knob before pressing the RESET button of Arduino.
Release RESET button for a second and then release play/stop knob.
When the music shield is beginning to record, the green and red LEDs will blink synchronous.
Press play/stop knob will stop recording.
The demo code for the shield is
#include <avr/io.h>
#include "config.h"
#include "filesys.h"
#include "player.h"
#include "vs10xx.h"
#include "record.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);//pin2-Rx,pin3-Tx(note: pin3 is actually later used as volume down input)
void setup()
{
Serial.begin(9600);
//Serial.println("Hello test!");
mySerial.begin(19200);// used for receiving command data from the iPod dock.
InitSPI();
InitIOForVs10xx();
InitIOForKeys();
InitIOForLEDs();
InitFileSystem();
//VsSineTest();
Mp3Reset();
}
void loop()
{
#if defined(__AVR_ATmega1280__)|| defined(__AVR_ATmega2560__)
// If play/stop button is pressed during boot, enter recording.
if (0== PSKey)
{
delay(20);
while(0 == PSKey);
delay(20);
Record();
}
#endif
Play();
while(1);
}
I'm trying to integrate it into this accelerometer code that will currently 'do something' when the arduino is tilted past 30 Degrees on the x or y axis. If there is a way of doing it with an 'if' statement then I am already set up for that.
// these constants describe the pins. They won't change:
const int groundpin = 66; // analog input pin 4 -- ground
const int powerpin = 67; // analog input pin 5 -- voltage
const int xpin = A11; // x-axis of the accelerometer
const int ypin = A10; // y-axis
const int zpin = A9; // z-axis (only on 3-axis models)
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
// Provide ground and power by using the analog inputs as normal
// digital pins. This makes it possible to directly connect the
// breakout board to the Arduino. If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop()
{
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
delay(100);
if (analogRead(xpin) > 589 ||analogRead(xpin) < 433||analogRead(ypin) > 589 ||analogRead(ypin) < 433 )
{
}
else
{
}
}
The problem being I do not know how and I need a hint from someone with more experience than myself.
Might I have to write or edit some library pages?
Is it the hardware on the Music Shield that is already set to record in this way? If so, can it be changed within the Arduino 1.0 software?
I'm not sure where to go from here. Thank you in advance for any light you can shed on this subject.
Stu