Posts with code

For my work, I'm mostly using Matlab for the control and the analysis of my experiments. I've also used a bit of the Processing (and Java) language, as well as basic C code for various projects involving Arduino microprocessors. This page lists posts mainly concerned with computer code, while the Arduino projects are in the Make section of my homepage.


  • Wed, 06/08/2011 - 16:34

    A Python script that's using OpenCV to open a video, loop it, and trigger playback via a command coming from the serial port (where in my case an Arduino is connected) or a key press. Playback stops after a timer has run out and commences after another trigger event.

  • Fri, 02/11/2011 - 12:25

    Below is a PDF of my presentation and the code for a tutorial on making elaborate multi-axes movies with Matlab. The tutorial was part of the "hallway salon" series that has become a tradition in the Daniel Lab.

    The code contained on this page contains a framework for saving movies from MATLAB that should be easily adaptable for your own work. I tried to add as many comments in the code, so it should be fairly self-explanatory.

  • Thu, 01/06/2011 - 17:49

    This page contains the source code for the Arduino-based laser trigger unit described in a separate post.

    I tried to insert comments in the code, so it should be pretty self-explanatory. To play and modify the code, you can copy and paste it into your Arduino IDE. (The line numbers in the code listing won't be copied.)

  • Sun, 01/02/2011 - 14:00

    For many applications in behavioral biology, it's nice to trigger events or devices (e.g. cameras, lights) when an animal moves into a specific region of a camera view. In order to trigger our lab's high-speed video cameras, I wrote a simple program in the Java language that uses an inexpensive web-cam to detect if objects move from one frame to the next. A region of interest can be set by clicking and dragging to position a red rectangle on the camera view. Thresholds can be changed to make the trigger more or less sensitive, and it can be toggled between an "armed" and "unarmed" mode.

  • Fri, 12/31/2010 - 14:15

    My second attempt at creating a moving sine wave is somewhat different than in the first example (see previous post). This time, I created a sine wave class, which during initialization creates an array holding the pixel values of a sine wave. I also added a Perlin noise class, for making a 2D noise pattern, as well as an image class to load an images. The position of each pattern can then be controlled with the mouse.

  • Fri, 12/31/2010 - 09:36

    Sick Sine Wave

    This is my very first interactive applet created in Processing. The speed and spatial frequency of this sinusoidal grating can be influenced by moving the mouse over the animation. X controls speed, Y controls the number of periods shown.