Wednesday, October 3, 2007

serial record


This is the code for operating two buttons on the micro controller. (pbasic)

' {$STAMP BS2}
' {$PBASIC 2.5}

' check if a button is pressed page 78 of text

check VAR Byte
learn VAR Byte
playBack VAR Byte
checkTwo VAR Byte
checkThree VAR Byte
counter VAR Byte
counterTwo VAR Byte(10)
counterTwoA VAR Byte(10)



DO


check = IN3
checkTwo = IN10
checkThree = IN0



'record from input once every 650 microsec...

FOR learn = 0 TO 9

' DEBUG ? IN10

LOW 5
' DEBUG ? IN0
PAUSE 650
'DEBUG ? checkTwo

IF IN10 = 0 THEN
' DEBUG "rec"
HIGH 14
counterTwo(learn) = 1
ENDIF
IF IN10 = 1 THEN
LOW 14
counterTwo(learn) = 0
ENDIF
' DEBUG ? learn


IF IN0 = 0 THEN
' DEBUG "rec"
HIGH 6
counterTwoA(learn) = 1
ENDIF
IF IN0 = 1 THEN
LOW 6
counterTwoA(learn) = 0
ENDIF
' DEBUG ? learn


'output data to serial port

IF IN3 = 0 THEN
FOR playBack = 0 TO 9
' DEBUG ? counterTwo(playBack)
IF counterTwo(playBack) = 1 THEN
' SEROUT 16, 16780, ["A"]
SEROUT 16, 16780, [DEC 1]
HIGH 14
PAUSE 500
ENDIF
IF counterTwo(playBack) = 0 THEN
SEROUT 16, 16780, [DEC 9]
LOW 14
PAUSE 500
ENDIF
IF counterTwoA(playBack) = 1 THEN
' SEROUT 16, 16780, ["B"]
SEROUT 16, 16780, [DEC 2]
HIGH 14
PAUSE 500
ENDIF
IF counterTwoA(playBack) = 0 THEN
SEROUT 16, 16780, [DEC 8]
LOW 14
PAUSE 500
ENDIF
NEXT
ENDIF

'light led each time the cycle ends

IF learn = 0 THEN
HIGH 5
PAUSE 500
ENDIF

NEXT



LOOP



This is the code for interfacing with processing (processing PDE)

import processing.serial.*;

Serial myPort; // The serial port

int[] num;
int counter;

void setup() {

frameRate(900);
size(200, 200);
background(51);
stroke(55);
noFill();
smooth();
println(Serial.list());



num = new int[10000000];


counter = 0;

myPort = new Serial(this, Serial.list()[1], 2400);

}

void draw() {
while (myPort.available() > 0) {
String inBuffer = myPort.readString();


if (inBuffer != null) {
print(inBuffer);
print("\n");
}
int conv = int(inBuffer);

if (conv == 8){
fill(255);
num[counter] = 8;
counter = counter + 1;
}
if (conv == 9){
fill(111);
num[counter] = 9;
counter = counter + 1;
}
if (conv == 1){
fill(111,0,255);
num[counter] = 1;
counter = counter + 1;
}
if (conv == 2){
fill(255,0,255);
num[counter] = 2;
counter = counter + 1;
}
triangle(30, 75, 58, 20, 86, 75);
}
}

Labels:


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?