First of all, before I begin with analog output, I have to remind myself something. When connecting a pot to my circuit remember to connect the middle pin to the BX and the other two to the power and ground. For some reason I keep forgetting this and almost burn my board or BX or whatever smells like burnt plastic as I happily connect the middle pin to power.
Till now I learned how to input and it's time to output analogically (if there is such word).... Why would I possibly want an output with a range greater than 0 or 1? Well, there some application that I know it might help - To create a mood (dim an LED); to built a toy or a watch (control the pulses of a servo motor), can listen to the radio (this is basically a guess. From the readings I understand that a filter circuit enables us to control the frequencies that reach a circuit, hence I am assuming that's how a radio works); I can play DJ (Thru tone generation I can control the frequencies so us humans can hear it - from 20 to 20,000hz). This last one reminds me that I have got to try this FreqOut command soon (I might try to integrate it into my midterm).
Using analog output, doesn't mean that I actually make my BX produce a varying voltage (it can't!) but I am producing a pseudo-analog voltage which is actually a variety of pulse widths. In other words - pulse width modulation (PWM)
Imagine Manhattan skyline, when all the buildings are replicas of the world trade center and they are all equal and equally spaced. The horizontal is the time and the vertical is the voltage - this is the graph to describe PWM. When the building and spaces between them are equal, then the effective voltage is about half the total voltage (imagine a horizontal line right in the center of the buildings). Lets say you shrink the width of these buildings, and as a result the distances between them grow, it affects the voltage and we get a lower affective voltage (the imaginary line is now close to the bottom of the buildings).
Here is the code for the pulsewidth modification:
Pulseout (pin, pulseWidth, state)
After managing to activate a servo motor and play with it's speed and pulse widths, I need to go home and think about my midterm. I have no idea of what my project would be. Whatever it'll be I'm sure it'll have fun results.
Here's a pot-dramatic picture of my circuit. The pot is there because I felt an urge to dim an LED.
This code helped me:
|
|
|