Pages: [1]   Go Down
Author Topic: Difference between PWM and tone() + some general questions  (Read 378 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 34473
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Experience, it's what you get when you were expecting something else.

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: