Go Down

Topic: Difference between PWM and tone() + some general questions (Read 407 times) previous topic - next topic

vertigo5

I am currently on project 6 of the arduino starter kit (light theremin),
and although I read the descriptions thouroghly, I fail to understand:
what is the difference between PWM and the tone() function?
why couldn't we just use the PWM to control the Piezo?
when would you use PWM normally, and when tone()?

other shorter and more general issues I wondered about:

1. is there a "correct" way to disconnect the arduino after running a script?
or should I just unplug it?
2. Should I reset or something after every use? or is it ok if the script stays on it till the next upload?
(I worry that running an old script with a different wiring might screw something up)
3. is it normal that some components are quite tricky to fit into the breadboard?
(specifically: photorsesistors, potentiometers, capacitors)


lots of questions but would appretiate any help!
Thanks,
Vertigo5

Grumpy_Mike

Quote
why couldn't we just use the PWM to control the Piezo?

Because PWM only give out one frequency. Changing the duty cycle with the analogue write function will not change the tone.
http://www.thebox.myzen.co.uk/Tutorial/PWM.html


1. Just unplug it.
2. If you change the hardware then you could get a clash of input / output connections so set it to a blank sketch before connecting anything to it. That is a sketch with nothing in the setup or loop functions.

3. Yes, that is why many people hate breadboard an never use it.

afremont


I am currently on project 6 of the arduino starter kit (light theremin),
and although I read the descriptions thouroghly, I fail to understand:
what is the difference between PWM and the tone() function?
why couldn't we just use the PWM to control the Piezo?
when would you use PWM normally, and when tone()?

other shorter and more general issues I wondered about:

1. is there a "correct" way to disconnect the arduino after running a script?
or should I just unplug it?
2. Should I reset or something after every use? or is it ok if the script stays on it till the next upload?
(I worry that running an old script with a different wiring might screw something up)
3. is it normal that some components are quite tricky to fit into the breadboard?
(specifically: photorsesistors, potentiometers, capacitors)


lots of questions but would appretiate any help!
Thanks,
Vertigo5


Using the built in arduino PWM (analogWrite), the frequency is unchanging.  It is always something around 490Hz, but the duty-cycle (on-off ratio) is changeable.

1)  Pretty much just unplug it.  The only problem I can think of off hand would be if you are writing to the EEPROM just as the power is pulled.

2) Leaving a script in flash between uses of the board will have no effect.

3) Different breadboards are like this.  Some would rather fold over a wire rather than let it plug in.  Some are too loose and some are really nice.  Cost has a lot to do with it.
Experience, it's what you get when you were expecting something else.

vertigo5

Thanks for the answers Grumpy_Mike and afremont!
I will soon look into better breadboards or just dive into soldering.

Go Up