|
Guys,
I have a lilypad with the standard accelerometer and a buzzer. I can read the accel just fine but if I use the tone library as well I can read the accel three times, make three tones, and then it all just hangs. Is this some wierd interrupt thing?
Code follows .. thx in advance.
#include <Tone.h> #include <bassdll.h> #include <debug.h>
#include <stdlib.h> // for malloc and free void* operator new(size_t size) { return malloc(size); } void operator delete(void* ptr) { free(ptr); }
// // Ardy Jacket // // leds, buzzers (left/right), vibrator, acelerometer // //
const int groundPin = 18; // analog input pin 4 -- ground const int powerPin = 19; // analog input pin 5 -- voltage const int xPin = 16; // x-axis of the accelerometer ANALOG const int yPin = 17; // y-axis ANALOG const int zPin = 18; // z-axis (only on 3-axis models) ANALOG
int ledPins[4]; int rightBuzzerPin = 6; int leftBuzzerPin = 7; int vibratorPin = 8; //int x,y,z;
void setup() {
Serial.begin(9600);
// Setup led pins for (int count = 0; count < 4; count++) { ledPins[count] = 2 + count; pinMode(ledPins[count], OUTPUT); }
pinMode(leftBuzzerPin, OUTPUT); pinMode(rightBuzzerPin, OUTPUT); pinMode(vibratorPin, OUTPUT);
pinMode(xPin, INPUT); pinMode(yPin, INPUT); pinMode(zPin, INPUT); }
// Read the accelerometer. void readAccel(int &x, int &y, int &z) {
x = analogRead(xPin); y = analogRead(yPin); z = analogRead(zPin);
}
Tone tone1; Tone tone2;
void loop() {
int x = 0, y = 0, z = 0; // Read the accelerometer readAccel(x,y,z);
char buffer[56]; sprintf(buffer, "(x,y,z) = (%d,%d,%d)", x, y, z); Serial.println(buffer); sprintf(buffer, "(x,y,z) = (%d)", NOTE_A4 + x / 100); Serial.println(buffer);
tone1.begin(rightBuzzerPin); tone1.play(NOTE_A4,100 ); // tone2.begin(leftBuzzerPin); // tone2.play(NOTE_A4); delay(800);
}
|