void loop()
{
heartrate--;
int analog1Offset;
int analog2Offset;
int analog3Offset;
int analog4Offset;
analogWrite(HEARTPIN, heartrate);
/* increments the 'heartbeat' LED on pin 11 downward. Every 256 times through the main loop
- it will overflow to (underflow?) to 255. */
periodold = (period + periodold) / 2;
//average new values with old ones for better stability.
period = getfrequency();
//jump over to the getfrequency tab to measure the ultrasound distance and convert it to an appropriate range.
/************************** Read the analog photoresistor inputs **************************/
int measuredValue = analogRead(1);
int constrainedValue = constrain(measuredValue, analog1Offset, 900);
analog1 = map(constrainedValue, analog1offset, 900, 255, 0);
measuredValue = analogRead(2);
constrainedValue = constrain(measuredValue, analog2Offset, 900);
analog2 = map(constrainedValue, analog2offset, 900, 255, 0);
measuredValue = analogRead(3);
constrainedValue = constrain(measuredValue, analog3Offset, 900);
analog3 = map(constrainedValue, analog3offset, 900, 0, 500);
measuredValue = analogRead(4);
constrainedValue = constrain(measuredValue, analog4Offset, 900);
analog4 = map(constrainedValue, analog4offset, 900, 255, 230);
/ take the analog inputs and scale them to a byte datatype. Note that there's some dead space at the top
- and bottom of the sensor values-- so that the sensor stays at "off" or goes to "100%" at the end of travel. */
/******************************* Apply volume and effects **********************************/
if (abs(periodold - period) > 25) {
decay = 255;
}
else {
decay = ((decay * analog4) / 255);
}
//if a new tone is produced, reset decay to full, otherwise increment it downward.
analog3buffer = float(analog3) / 200;
//convert sensor 3 to a floating point number in the range of pi/16 to pi/4
for (byte i = 0; i < SAMPLESIZE ; i++) {
playbufferelement = (analog2sine _+ (255-analog2)overtones) / 255;_
_ /* waveform selection-- as analog2 ranges from 0-255 it changes the tone from_
_ * a pure sine wave to a more complex wavetype. /
playbufferelement = playbufferelementcos(analog3bufferi);
/ Wah effect-- creates a variable comb filter. Note that as cos(0) = 1, when the input_
_ * from the sensor is 0, the waveform is unchanged /
playbufferelement = playbufferelement * analog1 * decay / 65025;_
_ //volume and decay. _
_ playbuffer = playbufferelement + 128;
//bias the values back to 0-255 for PWM output.
Serial.print("Measured value: ");
Serial.println(measuredValue);
}
}//end loop)*_