Unexpected events .... Arduino
in
Integration and Hardware
•
1 year ago
Hi
I'm having real problems trying to work this one out, so would be very grateful for any pointers.
I've hooked up 5 LDRs to one Arduino using a breadboard, and am sucessfully getting 5 seperate readings - one for each. They each trigger a seperate mp3 file to play when the reading drops below ambient-100 (hand placed over the LDR). The audio stops as soon as the hand is removed.
I'm having real problems trying to work this one out, so would be very grateful for any pointers.
I've hooked up 5 LDRs to one Arduino using a breadboard, and am sucessfully getting 5 seperate readings - one for each. They each trigger a seperate mp3 file to play when the reading drops below ambient-100 (hand placed over the LDR). The audio stops as soon as the hand is removed.
It works perfectly with 3 of the LDRs, but number 5 doesn't do anything at all when the light is blocked, and when a hand is placed over LDR 4 both it's own mp3 file, and the mp3 linked to LDR 5 play at the same time! I don't understand, as they're getting seperate readings from the photoresistors.
I've tried for hours to work out where the problem is stemming from, and am pretty sure that it's not the code. Oh, it would have been so easy if it was a typing mistake! lol
Does anyone have any ideas? ..... Please! (*desperation*)
Just in case you need it, here's the code:
import processing.serial.*;
import cc.arduino.*;
import ddf.minim.*;
import cc.arduino.*;
import ddf.minim.*;
Minim minim, minim2;
AudioPlayer player1, player2, player3, player4, player5, player6, player7, player8, player9, player10;
int ambient;
int ambient1 = ambient;
int ambient2 = ambient;
int ambient3 = ambient;
int ambient4 = ambient;
int ambient5 = ambient;
int ambient6 = ambient;
int ambient7 = ambient;
int ambient8 = ambient;
int ambient9 = ambient;
int ambient10 = ambient;
AudioPlayer player1, player2, player3, player4, player5, player6, player7, player8, player9, player10;
int ambient;
int ambient1 = ambient;
int ambient2 = ambient;
int ambient3 = ambient;
int ambient4 = ambient;
int ambient5 = ambient;
int ambient6 = ambient;
int ambient7 = ambient;
int ambient8 = ambient;
int ambient9 = ambient;
int ambient10 = ambient;
int photocellPin1 = 0;
int photocellPin2 = 1;
int photocellPin3 = 2;
int photocellPin4 = 3;
int photocellPin5 = 4;
int photocellPin2 = 1;
int photocellPin3 = 2;
int photocellPin4 = 3;
int photocellPin5 = 4;
Arduino arduino, arduino2;
void setup() {
println(arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino2 = new Arduino(this, Arduino.list()[1], 57600);
size(512, 200);
minim = new Minim(this);
player1 = minim.loadFile("quiet_bass.mp3", 2048);
player2 = minim.loadFile("3_tom.mp3", 2048);
player3 = minim.loadFile("egg.mp3", 2048);
player4 = minim.loadFile("fast_bongo.mp3", 2048);
player5 = minim.loadFile("high_1.mp3", 2048);
player6 = minim.loadFile("last_bass.mp3", 2048);
player7 = minim.loadFile("off_bongo.mp3", 2048);
player8 = minim.loadFile("scrape_click.mp3", 2048);
player9 = minim.loadFile("sticks.mp3", 2048);
player10 = minim.loadFile("bass.mp3", 2048);
}
println(arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino2 = new Arduino(this, Arduino.list()[1], 57600);
size(512, 200);
minim = new Minim(this);
player1 = minim.loadFile("quiet_bass.mp3", 2048);
player2 = minim.loadFile("3_tom.mp3", 2048);
player3 = minim.loadFile("egg.mp3", 2048);
player4 = minim.loadFile("fast_bongo.mp3", 2048);
player5 = minim.loadFile("high_1.mp3", 2048);
player6 = minim.loadFile("last_bass.mp3", 2048);
player7 = minim.loadFile("off_bongo.mp3", 2048);
player8 = minim.loadFile("scrape_click.mp3", 2048);
player9 = minim.loadFile("sticks.mp3", 2048);
player10 = minim.loadFile("bass.mp3", 2048);
}
void draw() {
int photocellReading1 = arduino.analogRead(photocellPin1);
int photocellReading2 = arduino.analogRead(photocellPin2);
int photocellReading3 = arduino.analogRead(photocellPin3);
int photocellReading4 = arduino.analogRead(photocellPin4);
int photocellReading5 = arduino.analogRead(photocellPin5);
int photocellReading6 = arduino2.analogRead(photocellPin1);
int photocellReading7 = arduino2.analogRead(photocellPin2);
int photocellReading8 = arduino2.analogRead(photocellPin3);
int photocellReading9 = arduino2.analogRead(photocellPin4);
int photocellReading10 = arduino2.analogRead(photocellPin5);
if(ambient1 == 0) ambient1 = arduino.analogRead(photocellPin1);
if (photocellReading1 < ambient1-100) {
if(player1.isPlaying()) {
int photocellReading1 = arduino.analogRead(photocellPin1);
int photocellReading2 = arduino.analogRead(photocellPin2);
int photocellReading3 = arduino.analogRead(photocellPin3);
int photocellReading4 = arduino.analogRead(photocellPin4);
int photocellReading5 = arduino.analogRead(photocellPin5);
int photocellReading6 = arduino2.analogRead(photocellPin1);
int photocellReading7 = arduino2.analogRead(photocellPin2);
int photocellReading8 = arduino2.analogRead(photocellPin3);
int photocellReading9 = arduino2.analogRead(photocellPin4);
int photocellReading10 = arduino2.analogRead(photocellPin5);
if(ambient1 == 0) ambient1 = arduino.analogRead(photocellPin1);
if (photocellReading1 < ambient1-100) {
if(player1.isPlaying()) {
}
else {
player1.play(0);
}
}
else {
if(player1.isPlaying()) {
player1.pause();
player1 = minim.loadFile("quiet_bass.mp3", 2048);
}
}
else {
player1.play(0);
}
}
else {
if(player1.isPlaying()) {
player1.pause();
player1 = minim.loadFile("quiet_bass.mp3", 2048);
}
}
if(ambient2 == 0) ambient2 = arduino.analogRead(photocellPin2);
if (photocellReading2 < ambient2-100) {
if(player2.isPlaying()) {
}
else {
player2.play(0);
}
}
else {
if(player2.isPlaying()) {
player2.pause();
player2 = minim.loadFile("3_tom.mp3", 2048);
}
}
if(ambient3 == 0) ambient3 = arduino.analogRead(photocellPin3);
if (photocellReading3 < ambient3-100) {
if(player3.isPlaying()) {
else {
player2.play(0);
}
}
else {
if(player2.isPlaying()) {
player2.pause();
player2 = minim.loadFile("3_tom.mp3", 2048);
}
}
if(ambient3 == 0) ambient3 = arduino.analogRead(photocellPin3);
if (photocellReading3 < ambient3-100) {
if(player3.isPlaying()) {
}
else {
player3.play(0);
}
}
else {
if(player3.isPlaying()) {
player3.pause();
player3 = minim.loadFile("egg.mp3", 2048);
}
}
else {
player3.play(0);
}
}
else {
if(player3.isPlaying()) {
player3.pause();
player3 = minim.loadFile("egg.mp3", 2048);
}
}
if(ambient4 == 0) ambient4 = arduino.analogRead(photocellPin4);
if (photocellReading4 < ambient4-100) {
if(player4.isPlaying()) {
}
else {
player4.play(0);
}
}
else {
if(player4.isPlaying()) {
player4.pause();
player4 = minim.loadFile("fast_bongo.mp3", 2048);
}
}
if(ambient5 == 0) ambient5 = arduino.analogRead(photocellPin5);
if (photocellReading5 < ambient5-100) {
if(player5.isPlaying()) {
else {
player4.play(0);
}
}
else {
if(player4.isPlaying()) {
player4.pause();
player4 = minim.loadFile("fast_bongo.mp3", 2048);
}
}
if(ambient5 == 0) ambient5 = arduino.analogRead(photocellPin5);
if (photocellReading5 < ambient5-100) {
if(player5.isPlaying()) {
}
else {
player5.play(0);
}
}
else {
if(player5.isPlaying()) {
player5.pause();
player5 = minim.loadFile("high_1.mp3", 2048);
}
}
else {
player5.play(0);
}
}
else {
if(player5.isPlaying()) {
player5.pause();
player5 = minim.loadFile("high_1.mp3", 2048);
}
}
if(ambient6 == 0) ambient6 = arduino2.analogRead(photocellPin1);
if (photocellReading6 < ambient6-100) {
if(player6.isPlaying()) {
}
else {
player6.play(0);
}
}
else {
if(player6.isPlaying()) {
player6.pause();
player6 = minim.loadFile("last_base.mp3", 2048);
}
}
if(ambient7 == 0) ambient7 = arduino2.analogRead(photocellPin2);
if (photocellReading7 < ambient7-100) {
if(player7.isPlaying()) {
else {
player6.play(0);
}
}
else {
if(player6.isPlaying()) {
player6.pause();
player6 = minim.loadFile("last_base.mp3", 2048);
}
}
if(ambient7 == 0) ambient7 = arduino2.analogRead(photocellPin2);
if (photocellReading7 < ambient7-100) {
if(player7.isPlaying()) {
}
else {
player7.play(0);
}
}
else {
if(player7.isPlaying()) {
player7.pause();
player7 = minim.loadFile("off_bongo.mp3", 2048);
}
}
if(ambient8 == 0) ambient8 = arduino2.analogRead(photocellPin3);
if (photocellReading8 < ambient8-100) {
if(player8.isPlaying()) {
else {
player7.play(0);
}
}
else {
if(player7.isPlaying()) {
player7.pause();
player7 = minim.loadFile("off_bongo.mp3", 2048);
}
}
if(ambient8 == 0) ambient8 = arduino2.analogRead(photocellPin3);
if (photocellReading8 < ambient8-100) {
if(player8.isPlaying()) {
}
else {
player8.play(0);
}
}
else {
if(player8.isPlaying()) {
player8.pause();
player8 = minim.loadFile("scrape_click.mp3", 2048);
}
}
if(ambient9 == 0) ambient9 = arduino2.analogRead(photocellPin4);
if (photocellReading9 < ambient9-100) {
if(player9.isPlaying()) {
else {
player8.play(0);
}
}
else {
if(player8.isPlaying()) {
player8.pause();
player8 = minim.loadFile("scrape_click.mp3", 2048);
}
}
if(ambient9 == 0) ambient9 = arduino2.analogRead(photocellPin4);
if (photocellReading9 < ambient9-100) {
if(player9.isPlaying()) {
}
else {
player9.play(0);
}
}
else {
if(player9.isPlaying()) {
player9.pause();
player9 = minim.loadFile("sticks.mp3", 2048);
}
}
if(ambient10 == 0) ambient10 = arduino.analogRead(photocellPin5);
if (photocellReading10 < ambient10-100) {
if(player10.isPlaying()) {
else {
player9.play(0);
}
}
else {
if(player9.isPlaying()) {
player9.pause();
player9 = minim.loadFile("sticks.mp3", 2048);
}
}
if(ambient10 == 0) ambient10 = arduino.analogRead(photocellPin5);
if (photocellReading10 < ambient10-100) {
if(player10.isPlaying()) {
}
else {
player10.play(0);
}
}
else {
if(player10.isPlaying()) {
player10.pause();
player10 = minim.loadFile("bass.mp3", 2048);
}
}
else {
player10.play(0);
}
}
else {
if(player10.isPlaying()) {
player10.pause();
player10 = minim.loadFile("bass.mp3", 2048);
}
}
println("Pin 1 = " + photocellReading1);
println("Ambient1 = " + ambient1);
println("Pin 2 = " + photocellReading2);
println("Ambient2 = " + ambient2);
println("Pin 3 = " + photocellReading3);
println("Ambient3 = " + ambient3);
println("Pin 4 = " + photocellReading4);
println("Ambient4 = " + ambient4);
println("Pin 5 = " + photocellReading5);
println("Ambient5 = " + ambient5);
println("Pin 6 = " + photocellReading6);
println("Ambient6 = " + ambient6);
println("Pin 7 = " + photocellReading7);
println("Ambient7 = " + ambient7);
println("Pin 8 = " + photocellReading8);
println("Ambient8 = " + ambient8);
println("Pin 9 = " + photocellReading9);
println("Ambient9 = " + ambient9);
println("Pin 10 = " + photocellReading10);
println("Ambient10 = " + ambient10);
delay(10);
}
void stop()
{
player1.close();
player2.close();
player3.close();
player4.close();
player5.close();
player6.close();
player7.close();
player8.close();
player9.close();
player10.close();
minim.stop();
super.stop();
}
{
player1.close();
player2.close();
player3.close();
player4.close();
player5.close();
player6.close();
player7.close();
player8.close();
player9.close();
player10.close();
minim.stop();
super.stop();
}
(I know I should be using arrays ... but I haven't learnt how to yet! :-/ )
Thanks in advance
Kate
1