by passing AC current through
Quoteby passing AC current throughAnd where does this AC come from?
To turn the LED red, pin1 is set HIGH and pin2 is set low, so the power goes one way. To turn it green, the polarity of the two pins is swapped, so the power goes the other way. Yellow is produced by rapidly switching between red and green, producing AC
QuoteTo turn the LED red, pin1 is set HIGH and pin2 is set low, so the power goes one way. To turn it green, the polarity of the two pins is swapped, so the power goes the other way. Yellow is produced by rapidly switching between red and green, producing ACYou are not producing AC. AC is alternating current, where the voltage changes from positive to negative 50 or 60 times per second. All you are doing is switching which way the current, at +5V, is flowing.
an electric current that reverses its direction at regularly recurring intervals
Pulsating dc and ac are the same, a variable flow of electrons. The primary difference is the "Reference"... If "AC" is "Referenced" from the most negative level them you could say "It''s Just pulsating DC. Whether it is sinusoidal, square rectangular (duty cycle not 50%) triangular.Come to think about the definition a little and you will see that the prime requirement for AC... The one Difference that sets AC apart from noise is just Periodicity.It is the periodicity that sets it apart and allows it to do useful and predictable work is it's periodicity.Noise can be called AC... Pink noise (audio) and White noise (Full Spectrum) and random impulse noise are AC but because of the lack of predictability, little real work can be done with them.If you put in place a device that passes AC only, a capacitor or a transformer will pass your "DC" very well. it will also filter the signal due to its reactance or response to an "AC" signal... again the Periodicity.As to the library it does produce a signal that makes the LED light up Yellow... So the difference is?Just the point of reference... Put it in the right place and your "DC" signal becomes "AC".Place a diode in series and you remove 1/2 of the DC signal... Just as a diode would with AC... and you have DC again... pulsating but of one polarity... The signal cannot pull down when the input goes to it's lowest point because the diode will not conduct in the reverse direction.
#if defined(ARDUINO) && ARDUINO >= 100#include "Arduino.h"#else#include "WProgram.h"#endif
Version 1.2 released with Arduino 1.0 support. Thanks PaulDriver for the patch!
I also have a library (toneAC) that does "AC" to drive a speaker at almost twice the volume as the standard tone library. This is possible because I alternate the 5 volts between two pins. In my case, it's designed to be extremely fast, so I use the Arduino's PWM pins and timer 1. This also allows for perfect switching between the two pins without any programming slowing things down.As a bonus, my library can also drive a bicolor two pin LED as yours does (one of my example sketches included with the library controls a bicolor LED with a pot to adjust the cycle speed). You may want to check out my source. As toneAC is designed for ultra speed and accuracy, you must use the timer 1 controlled PWM pins. It also is totally driven totally by port registers for the fastest and smallest code. Looking at my library may assist you. I also have a NewTone library thats a modified version of toneAC but allows you to specify what pin you want to drive a speaker with. This also may assist you with your library.While writing library using port registers and timers may be a little more challenging at first, it's really not that hard once you do it a few times. And, the benefits are many. Very small code size, very fast, color switching and duty cycle can all be done in the background, no reason for delay statements which can kill a project, etc.Best of luck with your project!Tim
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16