Difference between revisions of "2008 3.05"

From Media Design: Networked & Lens-Based wiki
Jump to navigation Jump to search
Line 31: Line 31:
  
 
=== Example ===
 
=== Example ===
<code>
+
 
 +
<code lang="python">
 +
 
 
import time, random
 
import time, random
 
import gst, pygst
 
import gst, pygst
Line 50: Line 52:
 
 
 
player.set_state(gst.STATE_NULL)
 
player.set_state(gst.STATE_NULL)
 +
 
</code>
 
</code>

Revision as of 00:00, 16 May 2008

Tech Day 3.05

In-class Problem Set

Analog Sensor / Python Class

Wiring the analog sensor

We use a voltage divider, as in this example from the Making Things Talk text:

File:Makingthings voltagedivider.png

Write the Python program

Create a "call and response" arduino application. program the arduino to read one or more inputs (*at least one* analog), send the data only in response to reading a byte from it's serial port (the call)

Write a simple "proof of concept" receiver (in Python)

Relativizing Analog Input

Use two variables, maxsensor and minsensor, to remember the highest and lowest sensor value your program as seen. Use these values to translate the sensor reading at any moment into a "scaler" that goes from 0 (when the sensor value is at the minimum) to 1 (sensor is at maximum).

Use your scaler to control a visual PyGame property (size, color, position of a drawn shape, image).

c.

CREATE a Class called Sensor to encapsulate your min / max sensor reading code.


Example

import time, random import gst, pygst

  1. pipe2_desc = 'videotestsrc ! ffmpegcolorspace ! ximagesink'

oggpath = '/home/murtaugh/Videos/personalchef.ogg'

  1. pipe2_desc = 'filesrc location=%s ! oggdemux ! theoradec ! ffmpegcolorspace ! ximagesink' % oggpath

player_desc = 'filesrc location=%s ! oggdemux ! theoradec ! videobalance name=bal contrast=2 ! ffmpegcolorspace ! ximagesink' player = gst.parse_launch(player_desc % oggpath) videobalance = player.get_by_name("bal")

player.set_state(gst.STATE_PLAYING)

for i in range(50): time.sleep(1) rval = random.random() videobalance.set_property("contrast", rval)

player.set_state(gst.STATE_NULL)