Your browser does not support the canvas tag.

Week 2


Douglas Engelbart Augmentation Research Center

Mother of all tech Demos 1

hyperlinks

interfacing

mouse

weird one handed keyboard

Week 2 ... Potentiometers!


But first, a word about soldering. When you solder you heat up very soft metal, it becomes a liquid and forms a bond where you are trying to make an electrical connection. This bond, however, is not physically very strong. Soldering is not structural - soldering and welding are two very different animals. Here's how to solder in bullet form.
Keep the tip of the iron clean - use a damp sponge while soldering and periodically clean (or "tin" the tip with tip tinner)
What is a potentiometer (or pot)? Simply put, it's an electric knob. Sometimes it will be called a variable resistor, which is also an accurate description of what it does - it variably resists the voltage.
It's actually easier to wire a pot than a button. The middle pole goes to an analog input pin. The other two poles are interchangeable - one goes to the 5v pin the other to ground. here's a picture of how to wire it.



DONT FORGET TO CHANGE THE [0] TO THE RIGHT NUMBER FOR YOUR MACHINE.

	import processing.serial.*;
	import cc.arduino.*;
	Arduino arduino;
	int analogPin = 0;
	float potX = 0; 
	void setup()
	{
	  size(400, 400); 
	  arduino = new Arduino(this, Arduino.list()[0], 57600); 
	}

	void draw()
	{ 
	  println ( arduino.analogRead(analogPin)); 
	}


	

Try swapping the ground and 5v and see what happens to the number.

In the following sketch we apply the pot to something on the screen. The "map" function is very useful for this - it allow us to remap an incoming number to another range, in this case the incoming range is between 0 and 1023, and we are mapping that value to a range between 0 and the width of the stage. Use the Processing API to look this (and other stuff) up.


	import processing.serial.*;
	import cc.arduino.*;
	Arduino arduino;
	int analogPin = 0;
	float potX = 0; 
	void setup()
	{
	  size(400, 400); 
	  arduino = new Arduino(this, Arduino.list()[0], 57600);
	  smooth(); 
	}

	void draw()
	{ 
	  background(200); 
	  int pot1 = arduino.analogRead(analogPin); 
	  potX = map(pot1, 0, 1023, 0, width); 
	  fill(0); 
	  ellipse (potX, 200, 6, 6); 
	}
	

PONG ... IT BEGINS

It's time to start thinking aobut PONG, which means making real pong before we can make augmented pong. Here's a good start. Add the Arduino and make the paddles move by moving potentiometers. There's a few things that might be new here, PVectors and classes. If they are, we cam recap how they work, and there's excellent tutorials on how to use them, but here's the short story. PVectors are just vairables that let us store two (or three, but 2 is all we need) float variables within it. So each PVector has a x and y value. At first it just makes things tidier, but we can use add() to add vectors together waving us some lines of code.
Classes (or objects) will let us make multiple balls really easily. In some CS classes everything is an object. It seems a like a lot of extra code at first but thinking in objects allows for much more complicated projects as your game expands.

BallClass ball; 
PVector player1, player2; 
int playerW = 15; // width of paddle
int playerH = 60; // hieght of paddle

void setup() {
  size(600, 400); 
  smooth();// make the graphics look purdy. 
  rectMode(CENTER); // draw rects from center
  player1 = new PVector(20, height/2); 
  player2 = new PVector(width -20, height/2); 
  ball = new BallClass();
}

void draw () {
  background (50);// background color
  rect(player1.x, player1.y, playerW, playerH); 
  rect(player2.x, player2.y, playerW, playerH); 
  ball.display();
}

class BallClass {
  PVector ballLoc; 
  int ballsize = 16; // width of ball
  BallClass() {
    ballLoc = new PVector(width/2, height/2);
  }
  void display() {
    ellipse(ballLoc.x, ballLoc.y, ballsize, ballsize);
  }
}

Project3: Use the demo Pong code to start making Pong
Homo Ludens
Read through page 14 in the text and be prepared to talk about it in class next week.