Friday, October 21, 2005

Group Project-Touch Sensor-Adore


Processing movie link

http://itp.nyu.edu/~sh1319/pcomp/pcomp19.mov
and
http://itp.nyu.edu/~sh1319/pcomp/pcomp20.mov


Using pot, I can move the location of the object on the screen.
Photocell sensor changes the color of the of the object.
Slide changes the shape of object. Sqare to ellipse.

processing & pcom

pic basic code

DEFINE OSC 4INCLUDE "modedefs.bas"DEFINE ADC_BITS 10DEFINE ADC_CLOCK 3DEFINE ADC_SAMPLEUS 10TRISA = %11111111adcon1 = %10000010
adcVar0 VAR WORD ' ir Create variable to store resultadcVar1 VAR WORD ' ir Create variable to store resultswitchVar var byteinputVar Var BYTE
pause 500main: ADCIN 0, adcVar0 ADCIN 1, adcVar1 serout2 portc.6, 16468, [DEC adcVar0,44,DEC adcVar1,44,DEC PORTB.6,13] serIN2 portc.7, 16468, [inputVar] debug inputVar PULSOUT portd.0 ,inputVar PAUSE 10GoTo main

processing code

import processing.serial.*;
Serial myPort; // The serial port int slide;int light;int button;
String accumulation = "";
void setup() { // List all the available serial ports: println(Serial.list()); size(255,255); // I know that the first port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); //prime the pump in case your microcontroller is stuck in serin myPort.write(65);
}
void draw() { background(0); fill(0,light,0); if (button == 1){ ellipse(slide,100,10,10); } else{ rect(slide,100,10,10); }}
void serialEvent(Serial p) { int input = myPort.read();
// if the last thing in was a carriage return, it means that a whole reading is ready if (input== 13) { String[] asText = accumulation.split(","); //separate out the reading based on the comma (44) int[] asNumbers = int(asText); //turn the text reading in to numbers, beware if there is a 13 still attached at the end println("accumulation " + accumulation ); if (asNumbers.length >=3){ light = asNumbers[0]/3; //scale it a bit based on the empirical readings of this sensor slide = asNumbers[1]/4; //easy scaling because it is a potentiometer which delivers solid 0-1020 button = asNumbers[2]; println("light " + light + " slide" + slide + " button" + button); } //now that you go a whole reading, clear your accumulation accumulation = ""; //now send something to satisfy the serin //in this case I actualy am sending information back but even if you are not just send anything back //my servo wants numbers 65- 250 and the mouse gives me numbers between 0 and width int servoRange = 250-65; float percentageAcross = mouseX/float(width); int servoOut = int(servoRange*percentageAcross) + 65; myPort.write(servoOut);
} else{ accumulation= accumulation + char(input); //if you did not hear 13, accumulate }
}

Sunday, October 16, 2005

Serial Out



It's hard to find default. Simple code from reference.

Tuesday, October 11, 2005

Look at the Servo Movement


Servo!!!




start:
pulseWidth var byte ' set up constants with the minimum and maximum pulsewidths minPulse CON 50
maxPulse CON 250 ' set up a constant with the time between pulses:
refreshPeriod CON 20 ' set an initial pulsewidth:
pulseWidth = minPulse
main: 'take the output pin low so we can pulse it high
Low PORTb.2 ' pulse the pin
PulsOut PORTb.2, pulseWidth ' pause for as long as needed:
Pause refreshPeriod ' change the angle for the next time around:
IF pulseWidth > maxPulse Then
pulseWidth = minPulse
Else
pulseWidth = pulseWidth + 1
Endif
GoTo main

Monday, October 03, 2005

Examples from Class

Servo

DEFINE OSC 40
start: pulseWidth var byte ' set up constants with the minimum and maximum pulsewidths minPulse CON 20 maxPulse CON 250 ' set up a constant with the time between pulses: refreshPeriod CON 20 ' set an initial pulsewidth: pulseWidth = minPulse
main: 'take the output pin low so we can pulse it high Low PORTC.3 ' pulse the pin PulsOut PORTC.3, pulseWidth ' pause for as long as needed: Pause refreshPeriod ' change the angle for the next time around: IF pulseWidth > maxPulse Then pulseWidth = minPulse Else pulseWidth = pulseWidth + 1 Endif GoTo main

Pulsout(blinking)

define osc 40
myadcvar var worddutycycle var byteblinky var byte
output portb.7output portb.0
pause 500
blinky = 0

while blinky < 10portb.7 = 1pause 500portb.7 = 0pause 500blinky = blinky +1 wend
portb.7 = 1
main:
for dutycycle

Dim

' This example takes an analog input on RA2 and uses it to generate' a duty cycle for the PWM command. The PWM command is used' to dim an LED on pin B0.
define osc 40 'set the clock at 40mhz
' Define ADCIN parametersDEFINE ADC_BITS 10 ' Set number of bits in resultDEFINE ADC_CLOCK 3 ' Set clock source (3=rc)DEFINE ADC_SAMPLEUS 15 ' Set sampling time in uS
adcVar VAR WORD ' ADC resultdutyCycle var byte ' Duty cycle for PWM
' Set PORTA to all inputTRISA = %11111111 ' Set up ADCON1ADCON1 = %10000010
output portb.7portb.7 = 1
main: ADCIN 2, adcVar ' convert ADC value to a byte value: dutyCycle = adcVar / 4 ' PWM the LED. The third parameter is the number of ' cycles to repeat the PWM. at 4MHz, 1 cycle = 5 ms. pwm portb.0, dutyCycle, 100 'increase for chunkiness
goto main

Week 3 Lighting up LEDs one by one!








By turning pot, LEDs turns on one by one.

Chip Programming

DEFINE OSC 4
include "modedefs.bas"
DEFINE ADC_BITS 10
DEFINE ADC_SAMPLEUS 50
ADCvar VAR WORD
TRISA = %11111111
ADCON1 = %10000010
Pause 500
output portb.7
output portb.6
output portb.5
output portb.4
output portb.3

low portb.7
low portb.6
low portb.5
low portb.4
low portb.3

main:
ADCIN 0, ADCvar
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10]
If ADCvar=>10
then
high portb.7
else
low portb.7
endif
if ADCvar=>200
then
high portb.6
else
low portb.6
endif
If ADCvar>=400
then
high portb.5
else
low portb.5
endif
if ADCvar>=600
then
high portb.4
else
low portb.4
endif
If ADCvar>=800
then
high portb.3
else
low portb.3
endif


GoTo main

Observation Project



Using LED lights and switchs, I tried to make letter "A".