basically, i have this project that produces sound when an LDR is covered and a piezo is hit. we have everything up but its just looping the same set of notes. any help would be good.
// audio and interactivity project
int abuttonPin = 1;
int bbuttonPin = 2;
int cbuttonPin = 3;
int dbuttonPin = 4;
int ebuttonPin = 5;
int fbuttonPin = 6;
int piezoPin = 8;
int footswitch = 9;
#include "pitches.h"
const int threshold = 5;
int notes[] = {
NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5,
}
;void setup () {
pinMode(abuttonPin, INPUT);
pinMode(bbuttonPin, INPUT);
pinMode(cbuttonPin, INPUT);
pinMode(dbuttonPin, INPUT);
pinMode(ebuttonPin, INPUT);
pinMode(fbuttonPin, INPUT);
pinMode(piezoPin, INPUT);
pinMode(footswitch, INPUT);
Serial.begin (31250);
}
void loop() {
int digitalRead(piezoPin);
if (footswitch = LOW) int notes (NOTE_A4 > NOTE_D5);
for (int abuttonPin = 0; abuttonPin < 3; abuttonPin++) {
// get a sensor reading:
int abuttonPinReading = analogRead(abuttonPin);
// if the sensor is pressed hard enough:
if (abuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[abuttonPin], 20);}
for (int bbuttonPin = 0; bbuttonPin < 3; bbuttonPin++) {
int bbuttonPinReading = analogRead(bbuttonPin);
if (bbuttonPinReading > threshold) {
tone(8, notes[bbuttonPin], 20);}
for (int cbuttonPin = 0; cbuttonPin < 3; cbuttonPin++) {
// get a sensor reading:
int cbuttonPinReading = analogRead(cbuttonPin);
// if the sensor is pressed hard enough:
if (cbuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[cbuttonPin], 20);}
for (int dbuttonPin = 0; dbuttonPin < 3; dbuttonPin++) {
// get a sensor reading:
int dbuttonPinReading = analogRead(dbuttonPin);
// if the sensor is pressed hard enough:
if (dbuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[dbuttonPin], 20);}
for (int ebuttonPin = 0; ebuttonPin < 3; ebuttonPin++) {
// get a sensor reading:
int ebuttonPinReading = analogRead(ebuttonPin);
// if the sensor is pressed hard enough:
if (ebuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[ebuttonPin], 20);}
for (int fbuttonPin = 0; fbuttonPin < 3; fbuttonPin++) {
// get a sensor reading:
int fbuttonPinReading = analogRead(fbuttonPin);
// if the sensor is pressed hard enough:
if (fbuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[fbuttonPin], 20);}
}
if (footswitch = HIGH) int notes (NOTE_DS5 > NOTE_GS5);
for (int abuttonPin = 0; abuttonPin < 3; abuttonPin++) {
// get a sensor reading:
int abuttonPinReading = analogRead(abuttonPin);
// if the sensor is pressed hard enough:
if (abuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[abuttonPin], 20);}
for (int bbuttonPin = 0; bbuttonPin < 3; bbuttonPin++) {
// get a sensor reading:
int bbuttonPinReading = analogRead(bbuttonPin);
// if the sensor is pressed hard enough:
if (bbuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[bbuttonPin], 20);}
for (int cbuttonPin = 0; cbuttonPin < 3; cbuttonPin++) {
// get a sensor reading:
int cbuttonPinReading = analogRead(cbuttonPin);
// if the sensor is pressed hard enough:
if (cbuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[cbuttonPin], 20);}
for (int dbuttonPin = 0; dbuttonPin < 3; dbuttonPin++) {
// get a sensor reading:
int dbuttonPinReading = analogRead(dbuttonPin);
// if the sensor is pressed hard enough:
if (dbuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[dbuttonPin], 20);}
for (int ebuttonPin = 0; ebuttonPin < 3; ebuttonPin++) {
// get a sensor reading:
int ebuttonPinReading = analogRead(ebuttonPin);
// if the sensor is pressed hard enough:
if (ebuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[ebuttonPin], 20);}
for (int fbuttonPin = 0; fbuttonPin < 3; fbuttonPin++) {
// get a sensor reading:
int fbuttonPinReading = analogRead(fbuttonPin);
// if the sensor is pressed hard enough:
if (fbuttonPinReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[fbuttonPin], 20);}
}
}
}
}
}
}
}
}
}
}
}
}
void noteOn (int cmd, int pitch, int velocity) {
Serial.print (cmd, BYTE);
Serial.print (pitch, BYTE);
Serial.print (velocity, BYTE);
}