help making simple audio sketch?

Hi there.

I am trying to learn right now how to make a simple sketch which will read from an analog PIN, dump the incoming values into a value called INPUT and then be able to do things to INPUT, like subtract from it, multiply it by another input, etc and then have it come out on an output.

but i am having a hard time figuring this out.

any help appreciated! thanks

The analogRead function will read the voltage on an analog pin, and return an integer value between 0 and 1023 inclusive that corresponds to the ratio of the voltage on the pin to Vref.

There are plenty of examples provided with the Arduino software that can be modified for your use.

const int INPUT_PIN = 0;

void setup() {
  //do some setup
}

void loop() {
  int input = analogRead(INPUT_PIN); //read the value of INPUT_PIN [0,1023]
  //do something
}

Good luck with whatever you want to achieve!

thanks to both of you but the thing i am really confused about is not how to get arduino to READ a pin, but how to tell it to send the data OUT on a pin.

all the sketches i can find that deal with sound in the examples use the TONE library and i am not trying to use that library.

so if I were to take the above code, how would i get it to the send that to , say output pin 11?

sorry if i sound like a fool.

(i have found some sketches which use digital write to turn a led on and off in response to an input, but this was also not what i wanted)

thanks

It is important to understand that the Arduino by it self has no way of outputting analog values. It has, however, the ability to use PWM and you do that by:

analogWrite(PWM_PIN, value); //PWM_PIN has to be a pin labeled PWM on the arduino, and the value [0,255]

thanks! so the other pins which are not labelled PWM are usefuk only for using an external DAC or R2r?

so much to learn!

much appreciated

loss1234: thanks! so the other pins which are not labelled PWM are usefuk only for using an external DAC or R2r?

so much to learn!

much appreciated

Yep.

oh sorry, all i meant was I am confused about how to get stuff out of the arduino.

in other words, it seems relatively easy to READ the inputs.

but once you have read the inputs, how do you get Arduino to send them out of the chip? and how do you decide if you should use one of the PWM outputs or just a normal output?

really i am just trying to make some simple audio processing sketches. a bit crusher or a ring modulator, i read LAB 3's tutorial on real-time audio processing but it was way over my head. and most other audio related sketches i find use the tone library.

i am sorry if i am not explaining myself very well.

i will try to write a simple sketch that shows what i mean.

thanks

10K samples per second would sound ok but really Arduino is not best for sound processing because to even get 10K / second would be running full out which would give you little processing time for doing other things.