Skip to content

March 9th in Review

March 9, 2011

As usual, our code from the morning is posted beneath the break.

From here, we’re taking on Project 12 under the “Projects” heading of this site:

Using a colored RGB LED, connect each of the pins of the LED to three pins on the Arudino that supports PWM.  Now, construct a color mixer that varies the levels of Red, Green and Blue the LED displays using three potentiometers connected to pins 0, 1, and 2 of the board.  This essentially uses the ideas brought forward in Project 8, but applying them to three pins of a colored LED rather than a single pin.

Also note that there were two concepts we covered this morning that are not presented here in the code. These were two different ways of creating conditional loops:

Have fun!

Read more…

Advertisements

March 2: This Week in Review

March 2, 2011

After the jump, you’ll find the code we wrote in class this morning. The circuit that accompanies this code has two LEDs (with your standard 220-ohm resister in series) attached to pin 9 and pin 13. Additionally, we have a 10K potentiometer with the two outer leads going to +5VDC and GND respectively, and the middle lead going to analog in 0.

Note that there are three new concepts here:

  1. Creating our own functions. Here, we create a “void” function called “blink.” This is a way of keeping a set of actions in one handy section of code, called a function. We can tell the program to jump to that function any time, and it saves us having to write the code out every single time we want to use it. Furthermore, we can pass along certain pieces of information, like values or variables, to use. We do this by including that information in the brackets when we call the function, and defining what we’ll use it for in the declaration of the function itself. More advanced info on functions at the Arduino Reference.
  2. analogRead. This is a function that only works with the “analog in” pins running along one side of the Arduino board. It reads the voltage coming into that pin, and then gives us a number between 0 and 1023, where 1023 would be 5VDC, 512 would be 2.5 VDC, and 0 would be 0 VDC. This process is called Analog-to-Digital-Conversion (ADC).
  3. analogWrite.  This writes a PWM value to your pin. PWM isn’t true analog, it’s faking it. What it really does is turn the pin on and off so fast that we can perceive it as outputing a lower voltage. We can control the “duty cycle” (i.e. what percentage of the time it’s flipped on vs. what percentage of the time it’s off to give a range of output values. It’s sort of the equivalent of flashing a white card and a black card at you back and forth really fast to trick you into think you’re seeing gray. This function only works on the Arduino pins marked with a ~ sign (Uno borads) or the letters PWM (on earlier Arduino boards).

For the afternoon, we’re going to try to make the changes to our code and circuit as outlined on this page: Project 9. Post your results in the comments section of that page!

Read more…

February 23: This Week in Review

February 23, 2011

After the jump, you’ll find a transcription of the program we “live-coded” in class today. It’s one solution to the problem we posed last week: Create a blinking light Arduino program that uses a switch to turn it on and off, and then use two other switches to make the light blink faster or slower.

 

THIS WEEK’S ALL-STAR CHALLENGES

If you’ve worked through this code and feel like you understand it, try to add these wrinkles to your code:

1) Add limits to the blinking rate, so there’s a maximum and minimum speed (bonus: this will also save your Arduino from crashing when it gets to negative values for delay times)

2) Change the method of speeding up or slowing down the blinking to be more proportional. (i.e.

3) PRO CHALLENGE: Set it up so that the blinking light is, by default, cyclically  speeding up and then slowing down when you turn it on. Then use the two additional buttons to change the rate of speeding up and slowing down.

 

Read more…

Class Introductions

February 7, 2011

Everyone – please leave a comment to this post  introducing yourself – background (i.e. programming, electronics, etc? other relevent past experience…), kind of work you make, interests in micro-controllers, etc.

Reply

Edit