The first picture is the working prototype where the waveshield detected the pressure against the force sensor. It still glitched in this form, because it would detect the sensor once and then stop reading the program entirely. I thought the problem was the SD card and the fact that the wires weren't soldered.
The second picture is the prototype right before I moved the wires to solder it to the circuit board. I was recording where the wires were in order to make sure I got everything in the right place. When I soldered it however, it refused to recognize the force sensor. I have no idea why.
The last picture is the final result of my revised project. It was in a cushion which was connected to my laptop so it could read the program. As I mentioned before, I couldn't make it work with the 9v batteries.
Here's the code I used:
#include
#include
#include "util.h"
#include "wave.h"
AF_Wave card;
File f;
Wavefile wave; // only one!
#define playcomplete(x) ROM_playcomplete(PSTR(x)) // save RAM by using program memory strings
#define servo 7
#define redled 9
#define eyeleds 18
#define mouthleds 17
#define midmouthleds 16
#define outermouthleds 19
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Wave test!");
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(redled, OUTPUT);
pinMode(servo, OUTPUT);
pinMode(eyeleds, OUTPUT);
pinMode(outermouthleds, OUTPUT);
pinMode(midmouthleds, OUTPUT);
pinMode(mouthleds, OUTPUT);
randomSeed(analogRead(0));
if (!card.init_card()) {
putstring_nl("Card init. failed!"); return;
}
if (!card.open_partition()) {
putstring_nl("No partition!"); return;
}
if (!card.open_filesys()) {
putstring_nl("Couldn't open filesys"); return;
}
if (!card.open_rootdir()) {
putstring_nl("Couldn't open dir"); return;
}
putstring_nl("Files found:");
ls();
}
void ls() {
char name[13];
int ret;
card.reset_dir();
putstring_nl("Files found:");
while (1) {
ret = card.get_next_name_in_dir(name);
if (!ret) {
card.reset_dir();
return;
}
Serial.println(name);
}
}
void pulseServo(uint8_t servopin, uint16_t p) {
digitalWrite(servopin, HIGH);
delayMicroseconds(600);
while (p--) {
delayMicroseconds(4);
}
digitalWrite(servopin, LOW);
delay(18);
}
uint8_t pumpkinstate = 0;
void loop() {
int distsensor, i;
long time;
/*
for (i=0; i<50; i++) {
pulseServo(servo,0);
}
for (i=0; i<50; i++) {
pulseServo(servo,400);
}
return;
*/
distsensor = 0;
for (i=0; i<8; i++) {
distsensor += analogRead(0);
delay(50);
}
distsensor /= 4;
putstring("Sensor = "); Serial.println(distsensor);
if (distsensor > 30 && distsensor <=450) {
playcomplete("5.WAV");
// } else if(distsensor > 150 && distsensor <=250)
// {
// playcomplete("RUBBER1.WAV");
// }else if(distsensor > 250&& distsensor <= 400){
// playcomplete("POP.WAV");
}else {
Serial.println("no signal");
}}
void ROM_playcomplete(const char *romname) {
char name[13], i;
uint8_t volume;
int v2;
for (i=0; i<13; i++) {
name[i] = pgm_read_byte(&romname[i]);
}
name[12] = 0;
Serial.println(name);
playfile(name);
Serial.println("test");
while (wave.isplaying) {
delay(5);
}
card.close_file(f);
}
void playfile(char *name) {
f = card.open_file(name);
if (!f) {
putstring_nl(" Couldn't open file"); return;
}
if (!wave.create(f)) {
putstring_nl(" Not a valid WAV"); return;
}
// ok time to play!
wave.play();
}
No comments:
Post a Comment