Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Troubleshooting / Re:  Led Matrix Processing, arduino control problems on: December 04, 2010, 04:07:28 am
Yes , thats my older post... I tried to delete it...well.

Ill do what you said, Thanks
2  Forum 2005-2010 (read only) / Troubleshooting / Led Matrix Processing, arduino control problems on: December 03, 2010, 05:37:55 pm
Hi, thanks for your time btw!

now, i created a led matrix in processing with some tutorials in the internet. next step was building a kind of controler with 4 directional moves (up, down, left, right) and enter/reset pixel. but im stuck with the code in the arduino, heres my code of arduino a and processing.
thaaaaaanks


teorically (for me), the controller is ok. but when i tried to move the led in my processing code they not work.
my guess will be that my arduino code is not sending the move of the led to the processing program.

Code:
const int PaddleLeft = 0;  // Paddle, posicion izq
const int PaddleRight = 100;  // Paddle, posicion der
const int PaddleRefresh = 20;  // Checa cada 20 ml el paddle
const int SerialRefresh = 2000;  // checa la posicion del Paddle cada 2 seg

int Y1_lesspin = 2;
int Y1_pluspin = 4;
int Y2_lesspin = 6;
int Y2_pluspin = 8;
int Y1=0;
int Y2=0;

void setup() {
 Serial.begin(9600);


 pinMode(Y1_lesspin, INPUT);
 pinMode(Y1_pluspin, INPUT);
 pinMode(Y2_lesspin, INPUT);
 pinMode(Y2_pluspin, INPUT);


}

void loop() {
    static int paddle1position = (PaddleLeft + PaddleRight) / 2; // Centra el Paddle 1 al comenzar el juego
    static int paddle2position = (PaddleLeft + PaddleRight) / 2; // Centra el Paddle 2 al comenzar el juego
    static unsigned long lastpaddlerefresh;  
    static unsigned long lastserialrefresh;  

  
int Y1_less = digitalRead( Y1_lesspin);
  
int Y1_plus = digitalRead( Y1_pluspin);

int Y2_less = digitalRead( Y2_lesspin);
  
int Y2_plus = digitalRead( Y2_pluspin);

//CONTROL 1

if (Y1_less == HIGH && Y1_plus == LOW && Y1>10)
{
Y1 = Y1 -2;

}
  if (Y1_less == LOW && Y1_plus == HIGH && Y1 < 245)

{

Y1 = Y1 +2;
}  

//CONTROL DOS

   if (Y2_less == HIGH && Y2_plus == LOW && Y2>10)

{
Y2 = Y2 -2;
  
}
  if (Y2_less == LOW && Y2_plus == HIGH && Y2 < 245)
{

Y2 = Y2 +2;
  
}  
  
  
  if(true)
  {
      Serial.print (0,BYTE);
      Serial.print (1,BYTE);
      Serial.print ((byte) Y1,BYTE);
      Serial.print (0,BYTE);
      Serial.print (2,BYTE);
      Serial.print ((byte) Y2,BYTE);
  }
      else
      {
    
      Serial.println (Y1);
    
      Serial.println (Y2);
    }
      delay (10);
}
3  Forum 2005-2010 (read only) / Troubleshooting / Re: Led Matrix Processing, arduino control problems on: December 03, 2010, 12:26:02 pm
My question is, what im doing wrong in the arduino code. The processing at the moment ia not a big deal.

Im a mediumi-noob at the programming stuff smiley-sad
4  Forum 2005-2010 (read only) / Troubleshooting / Re: Arduino Pong & Processing on: October 11, 2010, 11:04:11 pm


i know... the last week i posted a related article, i never founded  where to erase it. smiley
5  Forum 2005-2010 (read only) / Troubleshooting / Arduino Pong & Processing on: October 11, 2010, 11:01:49 pm
Hi guys, i have this huge problem.
i have a 2 players controler made in a breadboard, they are conected to my arduino.
 Mi Arduino its supose to send me data from 0 to 255. but it sends me rare characters. in the other hand my processing program doesnt recognize my data.
i wanted to asign the values from arduino to move the paddle, but it doesnt work. HELP plz!!!!  smiley-sad

My arduino code:
Code:
const int PaddleLeft = 0;  // Paddle, posicion izq
const int PaddleRight = 100;  // Paddle, posicion der
const int PaddleRefresh = 20;  // Checa cada 20 ml el paddle
const int SerialRefresh = 2000;  // checa la posicion del Paddle cada 2 seg

int Y1_lesspin = 2;
int Y1_pluspin = 4;
int Y2_lesspin = 6;
int Y2_pluspin = 8;
int Y1=0;
int Y2=0;

void setup() {
 Serial.begin(9600);
 
 pinMode(Y1_lesspin, INPUT);
 pinMode(Y1_pluspin, INPUT);
 pinMode(Y2_lesspin, INPUT);
 pinMode(Y2_pluspin, INPUT);
 

}

void loop() {
    static int paddle1position = (PaddleLeft + PaddleRight) / 2; // Centra el Paddle 1 al comenzar el juego
    static int paddle2position = (PaddleLeft + PaddleRight) / 2; // Centra el Paddle 2 al comenzar el juego
    static unsigned long lastpaddlerefresh;  
    static unsigned long lastserialrefresh;  

  
int Y1_less = digitalRead( Y1_lesspin);
  
int Y1_plus = digitalRead( Y1_pluspin);

int Y2_less = digitalRead( Y2_lesspin);
  
int Y2_plus = digitalRead( Y2_pluspin);

//CONTROL 1

if (Y1_less == HIGH && Y1_plus == LOW && Y1>0)
{
Y1 = Y1 -1;
 
}      
  if (Y1_less == LOW && Y1_plus == HIGH && Y1 < 255)

{

Y1 = Y1 +1;
}  

//CONTROL DOS

   if (Y2_less == HIGH && Y2_plus == LOW && Y2>0)

{
Y2 = Y2 -1;
  
}      
  if (Y2_less == LOW && Y2_plus == HIGH && Y2 < 255)
{

Y2 = Y2 +1;
  
}  
  
  
  
      Serial.print (0,BYTE);
      Serial.print (1,BYTE);
      Serial.print (Y1,BYTE);
      Serial.print (0,BYTE);
      Serial.print (1,BYTE);
      Serial.print (Y2,BYTE);
      
      delay (10);
}

My Processing code.
Code:

import processing.serial.*;
String portname = "COM16"; // aquí colocamos el puerto por el que recibimos el dato
Serial port; // Creamos un objeto llamado port de la clase Serial
// Variables para definir la pelota
float ball_x;
float ball_y;
float ball_dir = 1;
float ball_size = 5; // Radio
float dy = 0; // Dirección
// variables para definir la pala
int paddle_width = 5;
int paddle_height = 20;
int paddle_pos; // nueva posición
int paddle_ppos; // última posición
int dist_wall = 15;

int Y1=0;
int Y2=0;


void setup() {
size(255, 255);
rectMode(CENTER_RADIUS);
ellipseMode(CENTER_RADIUS);
noStroke();
smooth();
ball_y = height/2;
ball_x = 1;
// Abre el puerto al que esta conectada la tarjeta con una velocidad de (19200 bps)
port = new Serial(this, portname, 9600);

}

//Value
//Value
final byte START  = O;
final byte ESCAPE = 1;
final byte WAIT_Y1 = 2;
final byte WAIT_Y2 = 3;


byte state = START;
byte Y1  = 0;
byte Y2 = 0;

boolean processValue (byte value)

{
  switch (state)
  
  

  {
    case START;
    if (value == 0)
  {
    state = START;
  }
  
  return false;
  
  case ESCAPE:

if ( value == 1)
{
  state = WAIT_Y1;
}

else if ( value == 2)
{
  state = WAIT_Y2;
}

else
{
  state = START;
}
return false;


case WAIT_Y1;
      Y1 = value;
state = START;

return true;


case WAIT_Y2;
Y2 = value;
state = START;

return true;

}
return false;
}




void draw() {
background(51);
ball_x += ball_dir * 1.0;
ball_y += dy;
if(ball_x > width+ball_size) {
ball_x = -width/2 - ball_size;
ball_y = random(0, height);
dy = 0;
}
if (port.available() > 0) { // Si el dato está disponible,
paddle_ppos = paddle_pos; // guarda la ultima posición
paddle_pos = port.read(); // lee y almacena la nueva posición
}





// Desplaza la pala verticalmente en la pantalla
float paddle_y = constrain(paddle_pos, paddle_height, paddle_height);
// Testea si la pelota toca la pala
float py = width-dist_wall-paddle_width-ball_size;
if(ball_x == py
&& ball_y > paddle_y - paddle_height - ball_size
&& ball_y < paddle_y + paddle_height + ball_size) {
ball_dir *= -1;
if(paddle_pos != paddle_ppos) {
dy = (paddle_pos - paddle_ppos)/2.0;
if(dy > 5) { dy = 5; }
if(dy < -5) { dy = -5; }
}
}
// Si la pelota toca la pala o la pared, cambia de dirección
if(ball_x < ball_size && ball_dir == -1) {
ball_dir *= -1;
}

// Si la pelota toca la parte superior o inferior del borde, cambia dirección
if(ball_y > height-ball_size) {
dy = dy * -1;
}
if(ball_y < ball_size) {
dy = dy * -1;
}
// Dibuja la pelota
fill(255);
ellipse(ball_x, ball_y, ball_size, ball_size);
// Dibuja la paleta
fill(153);
rect(width-dist_wall, paddle_y, paddle_width, paddle_height);
}
6  Forum 2005-2010 (read only) / Troubleshooting / Re: Pong using 4 buttons. Programming problem :( on: October 08, 2010, 09:07:33 am
I know but our teacher told me... "Innovate", dont go by the easy way
7  Forum 2005-2010 (read only) / Troubleshooting / Re: Pong using 4 buttons. Programming problem :( on: October 07, 2010, 09:24:34 pm


this is how my breadboard and arduino looks.
plz help

girls are not made for this  :'(

any code improvement will be useful

UPDATE:
 
changed my code to
thanks for the help, now i dont know waht to do with this haha  ;D
C ya!

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(4, INPUT);
  pinMode(6, INPUT);
  pinMode(8, INPUT);
}

void loop() {
  int sensorValue2 = digitalRead(2);
  int sensorValue4 = digitalRead(4);
  int sensorValue6 = digitalRead(6);
  int sensorValue8 = digitalRead(smiley-cool;
  
  Serial.println(sensorValue2, DEC);
  Serial.println(sensorValue4, DEC);
  Serial.println(sensorValue6, DEC);
  Serial.println(sensorValue8, DEC);
  
}
8  Forum 2005-2010 (read only) / Troubleshooting / Pong using 4 buttons. Programming problem :( on: October 07, 2010, 01:49:12 pm
Hi guys, i have a huge problem. hope someone can help me smiley

i have a breadboard (protoboard), with 4 buttons (the classic  square button with four pins).

they are attached to my arduino pins 2,4, 5, 6.
and other cables connected to 5v and ground.

my problem is, that i dont know how arduino recive the info.
i want to use the 4 buttons to create a 2 player controler to play pong.

here is my code.

thanks for your help and time  smiley

int btnpl1a = 2;
int btnpl1b = 4;
int btnpl2a = 5;
int btnpl2b = 6;

char paddleleft;
char paddleright;

void setup()
{
  Serial.begin (9600);
  pinMode(butpin, INPUT);
  pinMode(but2pin, INPUT);
}

void loop()
{
 /* if (Serial.available()){
    paddleleft = Serial.read();
    paddleright =Serial.read();
  }
  
  if (val == 'H'){
 digitalWrite   */
 paddleft = digitalRead(btnpl1a);
 paddleleft = digitalRead(btnpl1b);
 if ( btnpl1a == 'H'){
   paddleleft=paddleleft/4;
 }
if ( btnpl1b == 'H'){
   paddleleft=paddleleft/4;
 }
paddleleft = digitalRead(btnpl1b); // read the input pin
 
 Serial.println(paddleleft,BYTE);

paddleright = digitalRead(btnpl2a,btnpl2b);    // read the input pin
paddleright = paddleright/4;
Serial.println(paddleright,BYTE);
  
  
  
}



delay (75)
Pages: [1]