October 20, 2005
PComp Assignment 6
Bought my motor have not completed this lab because I haven't been able to find a H-Bridge.
Posted by sj695 at 11:22 PM
October 13, 2005
PComp Assignment 5
This week we are sending and recieving data to Processing via the serial port. In this lab i moved a circle around the screen with a potentiometer. Here's the code:
-- Processing CODE --
/* Serial call-and-response
by Tom Igoe (with adjustments by Dano)
Sends a byte out the serial port, and reads 3 bytes in.
Sets foreground color, xpos, and ypos of a circle onstage
using the values returned from the serial port
Updated October 12, 2004
*/
import processing.serial.*;
Serial myPort; // The serial port
int redNess = 255; // fill color
int[] serialStuff= new int[3];; //where we keep all the incoming stuff
int serialCount = 0; // a count of how many bytes we receive
int xpos= width/2;; // Starting position of the ball
int shape =65;
void setup() {
size(255, 255); // stage size
noStroke(); // no border on the next thing drawn
myPort = new Serial(this, Serial.list()[0], 9600);
serialWrite(65); // send a capital A to start the MC sending
}
void draw() {
background(0);
fill(redNess,0,0);
// Draw the shape
if (shape==65){ //switch value is 65 or 66 (I added 65 to the normal values 0 and 1)
ellipse(xpos, 100, 50, 50);
}else{
rect(xpos,100,50,50);
}
}
void serialEvent() { //this function gets called when something happens involving the serial port
//serial is a special variable provided by processing to give you the oldest byte waiting to be read
// add the latest byte from the serial port into the correct slot in your byte array
serialStuff[serialCount] = myPort.read();
serialCount++;
// if we have 3 bytes, parse the string:
if (serialCount> 2 ) {
redNess = 2* serialStuff[0];
xpos = serialStuff[1];
shape = serialStuff[2];
// after you got them all, go back to putting the bytes in the first slot in the array again
serialCount = 0;
// get a number between 0 to 255 for the mouseX
//if your stage is bigger than 255 //int mouseXIn0to255 = 255*mouseX/width
//send out the mouseX to postion the servo motor
myPort.write(mouseX);
}
}
-- PIC BASIC CODE --
DEFINE OSC 4
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEuS 20
lightVar var byte
potVaR VAR BYTE
switchVar var byte
inByte var byte
input portb.7
main:
switchVar = portb.7 + 65 //make it readable
adcin 0, potvar
adcin 2, lightvar
serout2 portc.6, 16468, [lightVar,potVar,switchVar]
serin2 portc.7, 16468, [inbyte]
Pulsout portd.0, inByte
PAUSE 10
goto main
Posted by sj695 at 11:17 PM
October 06, 2005
PComp Assignment 4
It's amazing how much we're learning in PComp. We're in week 4 and programing a computer chip to control a servo. So this week we're programming a pic chip to control a servo with a potentiometer. Each week I feel like a painter learning how to create more colors. Here's the code:
DEFINE OSC 4
start:
INCLUDE "modedefs.bas"
' Define ADCIN parameters
' Set number of bits in result
DEFINE ADC_BITS 10
' Set clock source (3=rc)
DEFINE ADC_CLOCK 3
' Set sampling time in microseconds
DEFINE ADC_SAMPLEUS 10
' Set PORTA to all input
TRISA = %11111111
' Set up ADCON1 analog and right justify the result
adcon1 = %10000010
'define adc vars
adcVar0 VAR WORD 'Create variable to store result
'set a var for the pulsewidth- this tells the motor where to go
pulseWidth var byte
'thes values can be vary with different motors
minPulse CON 75
maxPulse CON 250
refreshPeriod CON 20
main:
'read adc data
ADCIN 0, adcVar0
'message the numbers so the value from the potentiometer matches the max and min of the servo
adcVar0 = (adcVar0/4) + 75
if adcVar0 >= 250 then
adcVar0 = 250
else
adcVar0= adcVar0
endif
'assign pulseWidth to the position of the potentiometer
pulseWidth = adcVar0
'set the pin low
low PORTC.3
'pulse the pin
PulsOut PORTC.3, pulseWidth
'pause
pause refreshPeriod
GOTO main
Posted by sj695 at 10:55 PM
September 29, 2005
PComp Assignment 3
For this week's assignment we are to communicate with a computer with our pic chip via the serial port. In the last week's lab I used a potentiometer instead of a switch to turn on the led, so this weeks lab was quite simple requiring nothing more than code midification. I must say it was quite amazing to see those numbers run down the screen in hyperterminal.
Here is the code I used:
' PicBasic Pro program to display result of
' 10-bit A/D conversion through serial at 9600 baud
'
' Connect analog input to channel-0 (RA0)
' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
ADCvar VAR WORD ' Create variable to store result
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
Pause 500 ' Wait .5 second
main:
ADCIN 0, ADCvar ' Read channel 0 to adval
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10] ' print it to serial out,
' with linefeed and carriage return (10, 13)
GoTo main ' Do it forever
Posted by sj695 at 10:38 PM
September 28, 2005
OBSERVATIONS PROJECT

Have sensors built into the doors that will measure sound.
Posted by sj695 at 06:56 PM
OBSERVATIONS PROJECT
Gives people personal space.
Posted by sj695 at 06:55 PM
OBSERVATIONS PROJECT
Used for shared/couple sitting
Posted by sj695 at 06:54 PM
September 22, 2005
PComp Assignment 2

For our second Physical Computing lab assignment we had to program a pic chip using a version of Basic.
Day 1
Last night I was able to get a LED to blink by writing the following code:
'Define the clock speed
DEFINE OSC 4
'These are the ports i'm working with
OUTPUT portb.1 '34 Pin Number
OUTPUT portb.4 '37 Pin Number
OUTPUT portb.7 '40 Pin Number
'Start Main Function
main:
' Turn on Port 1
HIGH portb.1
' Leave on for half a second
PAUSE 500
'Turn off Port 1
LOW portb.1
'Turn off for half a second
PAUSE 500
' Go back and repeat
goto main
Seems simple, but the most difficult portion of the Lab was setting up the bread board. After receiving help from other students in the lab I had the board setup in 2 hours of course I also had to solder and wire my switch (I didn't use a switch in assignment 1). The programming took about 15 minutes.
Day 2
Today I disassembled my board to make sure i knew what was going on and to aslo add and program my switch. Reassembling my board was really helpful and I feel like I have a much clearer idea of what's going on. Here is the code I used to turn the LED on and off with the switch:
input portb.0
output portd.1
main:
if portb.0 = 1 then ' if the switch is closed on pin RB0
low portd.1 ' set pin RD1 low
else
high portd.1 ' set RD1 high
endif
goto main
I also added a potentiometer to fad the LED when the switch was on, I was going to attempt to start next weeks lab but decided to wait.
Posted by sj695 at 05:19 PM | Comments (0)
September 12, 2005
First PCOMP Entry
This is my first Physical Computing Entry, not much here now check back later.
Posted by sj695 at 07:10 PM