Reading serial value - Major problems
hi have took apart air swimmer ( inflatable shark controller) , have soldered few wires on bypass each of buttons (left right , down) need send low signal when keyboard button pressed. low signal allows logic board on controller send correct infrared signal.
i have no idea why code isn't working , have went through 3 controllers trying right. have ideas?
arduino code -
anyone ideas helpful im loosing plot
i have no idea why code isn't working , have went through 3 controllers trying right. have ideas?
code: [select]
import processing.serial.*;
import processing.video.*;
serial port;
capture cam;
int val;
color fillval = color(126);
void setup() {
string portname = serial.list()[0];
port = new serial(this, portname, 9600);
size(550, 400);
// if no device specified, use default.
cam = new capture(this, 550 , 400);
}
//key detection begin
void keypressed() {
if (key == coded) {
if (keycode == up) {
port.write(65);
fillval = 255;
} else if (keycode == down) {
port.write(66);
fillval = 0;
} else if (keycode == right) {
port.write(67);
fillval = 100;
} else if (keycode == left) {
port.write(68);
fillval = 200;
}
} else {
fillval = 126;
}
}
//* void keyreleased() {
// if (key == coded) {
// if (keycode == up) {
// port.write(69);
// fillval = 0;
// } else if (keycode == down) {
// port.write(70);
// fillval = 255;
// } else if (keycode == right) {
// port.write(71);
// fillval = 200;
// } else if (keycode == left) {
// port.write(72);
// fillval = 100;
// }
// } else {
// fillval = 126;
// }
//}
//key detection end
void draw() {
//camera code begin
if (cam.available() == true) {
cam.read();
image(cam, 0, 0);
//camera code end
//dashboard interface begin
fill(100); //left big circle
ellipse(80,350,100,100); // left big circle
fill(100); // right big circle
ellipse(475,350,100,100); // right big circle
fill(100); // large rectangle
stroke(100); // large rectangle
rect(0, 350, 550, 75); // large rectangle
fill(0,100,0); // left radar circle
stroke(0); // left radar circle
ellipse(80,350,90,90); // left radar circle
fill(200); // left control stick
stroke(0); // left control stick
rect(180, 360, 10, 75); // left control stick
fill(200); // left control stick
stroke(0); // left control stick
rect(205, 360, 10, 75); // left control stick
fill(200); // right control stick
stroke(0); // right control stick
rect(320, 360, 10, 75); // right control stick
fill(200); // right control stick
stroke(0); // right control stick
rect(355, 360, 10, 75); // right control stick
fill(255,0,0); // right control stick
stroke(0); // right control stick
rect(175, 360, 45, 10); // right control stick
fill(0,100,0); // right control stick
ellipse(475,350,90,90); // right control stick
fill(200); // right control stick
stroke(0); // right control stick
rect(180, 360, 10, 75); // right control stick
fill(200); // right control stick
stroke(0); // right control stick
rect(205, 360, 10, 75); // right control stick
fill(255,0,0); // right control stick
stroke(0);// right control stick
rect(320, 360, 45, 10); // right control stick
fill(255,0,0); // left control stick
stroke(0); // left control stick
rect(175, 360, 45, 10); // left control stick
fill(100); //entre clock
rect(220, 320,100,30);// centre clock
fill(100); //entre clock
stroke(0);
rect(225, 325,90,20);// centre clock
//interface end
}
}
arduino code -
code: [select]
char val; // data received serial port
void setup(){
pinmode(3,output);//add led on pin 13
pinmode(5,output);//add led on pin 13 kicks
pinmode(7,output);//add led on pin 13 kicks
pinmode(9,output);//add led on pin 13 kicks
serial.begin(9600);//init serial library (make sure processing sending data @ same baud rate)
}
void loop() {
digitalwrite(3, high); // turn led on
digitalwrite(5, high); // turn led on
digitalwrite(7, high); // turn led on
digitalwrite(9, high); // turn led on
if (serial.available()) { // if data available read,
val = serial.read(); // read , store in val
}
if (val == 'a') { // if h received
digitalwrite(3, low); // turn led on
digitalwrite(5, high); // turn led on
digitalwrite(7, high); // turn led on
digitalwrite(9, high); // turn led on
} else {
digitalwrite(3, high); // otherwise turn off
}
if (val == 'b') { // if h received
digitalwrite(3, high); // turn led on
digitalwrite(5, low); // turn led on
digitalwrite(7, high); // turn led on
digitalwrite(9, high); // turn led on
} else {
digitalwrite(5, high); // otherwise turn off
}
if (val == 'c') { // if h received
digitalwrite(3, high); // turn led on
digitalwrite(5, high); // turn led on
digitalwrite(7, low); // turn led on
digitalwrite(9, high); // turn led on
} else {
digitalwrite(7, high); // otherwise turn off
}
if (val == 'd') { // if h received
digitalwrite(3, high); // turn led on
digitalwrite(5, high); // turn led on
digitalwrite(7, high); // turn led on
digitalwrite(9, low); // turn led on
} else {
digitalwrite(9, high); // otherwise turn off
}
}anyone ideas helpful im loosing plot
quote
i have no idea why code isn't working a
can tell more explicit did expect , got?
a quick @ code reveals
if (serial.available()) { // if data available read,
val = serial.read(); // read , store in val
}
i allways use if (serial.available() > 0) - more explicit
Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > Reading serial value - Major problems
arduino
Comments
Post a Comment