# May 9, 2013: Tree Fractal with Processing

After getting the Theramin working, we spent the last part of the meeting going back to writing some Processing code.

If you have a Sketchpad account, go to our Studio Sketchpad site at: coderdojogvl.sketchpad.cc and look at tonight’s project: Tree Fractal

The code is up on the Sketchpad site, and you can get there from the image below…

Running short on time, we did not get to spend much time with this, but here’s the main take-away from this code: Functions

(Click on the VIEW SOURCE link in the above sketch to go to Studio Sketchpad site and see Mrs. Anne’s program code.)

We’ve been using code functions without even realizing it.   A very simple and quick explanation of a function is that it is a block of reusable code that your declare (write) once and then you can use it over and over again simply by calling the function and sending it any values (called parameters) that it might need to work with.  The function may “do” something itself (draw a picture, make a sound, etc.) or it will often return a new value back to the main program.

A much better and more detailed description of a function can be found on the Arduino website here: http://arduino.cc/en/Reference/FunctionDeclaration if you are interested.

In the Tree Fractal program, we have a function called “branch”.  Don’t worry too much about the details inside of the branch function – that’s some pretty advanced fractal mathmatics.

### Challenge

Since we ran out of time, study the Tree Fractal program.  On Studio Sketchpad (if you’ve made an account) you can CLONE the original program, or just copy and paste the code into a new Processing sketch on your PC, and experiment with changing different values and see what happens.

Try changing the value of the branch parameter on line 13 or the 0.66 value on line 20? (hint: don’t change the values radically – small changes here will have a big effect)

# May 9, 2013: Amazing Musical Theremin

### Goal

Let’s build a musical Theremin using the Arduino Esplora.

Leon Theremin was a Russian inventor who created the a musical instrument in 1928 that could be played without touching the instrument simply by moving your hands in the air above it.

Here’s a clip of Sheldon playing his Theramin from The Big Bang Theory:

### Background

We’re going to use the light sensor to control what tone we send to the buzzer on the Esplora.  Because a constantly sounding tone can be amazingly annoying, we’ll use the slider to be an off-on switch for the Theremin.

### Let’s write the code

Let’s start by reading the slider to use as an off-on switch and also read the light sensor, and print out those values to the serial monitor just to make sure everything is working to this point.

At this point, you should be able to see the sensor values on the serial monitor, and moving the slider bar or covering the light sensor with your hand should change these values.

We’re going to use the MAP function to translate the values from the light sensor to different musical tones.  The light sensor can measure from 0 to 1000 (more or less – it really goes from 0 to 1023, but 1000 is a good number).  From testing, tone values from 100 to 2400 should be pretty good use.  MAP will let us change the light values to appropriate tone values.

(Note: the serial output is commented out this version, because we’re really past the point of debugging, but uncomment those lines if you’re not working correctly.)

# We’re Moving!

Important Note-

Next Week – May 9th’s meeting, we will moving to the new home of The Iron Yard at 2 North Main St., Greenville.  It’s right downtown at the intersection of Washington and Main – you may remember it as the old Windstream building.

Here’s a map!

Parking: The Spring Street Garage at Washington and Spring is closest, but will cost a few dollars to park.  There is also limited parking in a parking deck above Greenville Transit Authority and it is free after 6:00 pm.

# May 2, 2013: Tilt-a-sketch w/ Esplora plus Processing

### Goal

Using the accelerometer sensor built into the Esplora, we’re going to make a Tilt-a-Sketch similar to Etch-a-sketch.  The drawing action will be controlled by tilting / moving the Esplora in space.

Lesson Learned #1:

When working with the Arduino Esplora, a good idea is to start up by opening and uploading a simple program and make sure everything is working fine to begin with before you get too far along and get frustrated when something’s not working.  If a simple program does not work – be sure to check to the port and board type in the Arduino set-up.

Lesson Learned #2:

Save OFTEN!  Save – Save – Save

### Starting out

Let’s start simple and just see if we can read sensor values from the accelerometer and display values in the serial monitor.

If this code works, you should be able to open the serial monitor and watch the results from the reading the accelerometer.

Lesson Learned #3:

Watch out for the Esplora changing ports when you start using the Mouse.start() function!  You may have to change the ports at this point.

### Processing!

So, we’ve got the Esplora behaving like a mouse – Let’s add Processing to the mix and write a quick Processing sketch to be our Tilt-a-sketch.

Processing code:

Now, when the Processing sketch is running on the PC and the Arduino sketch is running on the Esplora – you’ve done it! Tilting / moving the Esplora will make a drawing on the processing canvas.

### Challenge

Add code to the Esplora sketch to make one of the buttons function as a mouse button click. There’s already some code in our Processing sketch that will do something every time a mouse button is pressed, just need to make a mouse button behavior on the Esplora. You may want to use the Ardiunio Esplora.ReadButton function (http://arduino.cc/en/Reference/EsploraReadButton) to trigger a MouseClick function (http://arduino.cc/en/Reference/MouseClick)

# April 25, 2013: Processing!

For the second half of the meeting, we started looking at the Processing programming language.  Processing is actually more than just a language, it is actually a language + programming environment (sometimes called and IDE = Integrated Development Environment).

Processing shares a lot in common with Arduino programming, and is an excellent way to extend what we are learning with Arduino devices to also be used in a more general-purpose language.

## Getting Started

• With Processing, programs are called “sketches” – same as Arduino.  When you create a new sketch (program) – Processing will automatically make a new folder to hold the program.
• All your sketches can be seen in your sketchbook – use your toolbar and go to PROCESSING >> FILE  >> SKETCHBOOK to see sketches on your computer.
• Also useful is all the example programs that are included.  Look at menu option PROCESSING >> FILE >> EXAMPLES.

There’s a website called Sketchpad.cc that allows people to program, run, share, and even share in editing the sketches.  Anne has set up area on sketchpad just for CoderDojo: Greenville here:  http://coderdojogvl.sketchpad.cc/ .

## Color Drops Processing Sketch

Our very first Processing Sketch was a program that randomly “drops” color drops on a screen area.

Here’s the source code we worked on in class:
(it’s not as bad as it looks – we’ve added a lot of comments in orange-ish to help understand)

# April 25, 2013: Arduino Esplora + Fix-It Felix

This was our new Electronics-track student’s second week of getting to work the Ardiuno Esplora and we focused for the first half of the meeting on how to program the Esplora to be a game controller for the Fix-It Felix! game.