Quantcast
Channel: Arduino - Processing 2.x and 3.x Forum
Viewing all 747 articles
Browse latest View live

Movement traces

$
0
0

Hello everybody,

any suggestions how I could merge my code below (movement tracing through for now a simple box) with e.g. this (http://studio.processingtogether.com/sp/pad/export/ro.9ldYvJUyiXGzi/latest) sketchpad code in which the trace fades slowly. I getting actual sensor data and am not using the mouse. I am trying to make the movement interpretation 'feel' more natural.

All suggestions or hints are super welcome Thank you already!!

import processing.serial.*;

Serial myPort;
int linefeed = 10; // Linefeed in ASCII int numSensors = 3; // we will be expecting for reading data from 3 sensors float sensors[]; // array to read the 3 values float pSensors[];

void setup() { size(1350, 800, P3D);
// List all the available serial ports in the output pane. // You will need to choose the port that the Wiring board is // connected to from this list. The first port in the list is // port #0 and the third port in the list is port #2. println(Serial.list());

myPort = new Serial(this, Serial.list()[2], 115200); // read bytes into a buffer until you get a linefeed (ASCII 10): myPort.bufferUntil(linefeed);

}

void draw() { if((pSensors != null)&&(sensors != null)) {

// now do something with the values read sensors[0] .. sensors[2]
 //First I find all my rotation angles in radians so that center screen is (0,0)

float rotx = (sensors[0]*PI)/180;
float roty = (sensors[1]*PI)/180;
float rotz = (sensors[2]*PI)/180;
//float roty = 0;

background(0);
stroke(0, 0, 200);
//line (0,20,420,20); // monitor bar
fill(255);
textSize(1);
text (" rotateX(" + rotx +" pi)"+" , rotateY("+roty+" pi)"+" , rotateZ("+rotz+" pi)", 0,10);
fill(0, 0, 200);

translate(610, 380, 0); // center drawing start point in screen  180 TO 380

strokeWeight(1);
stroke(50);

line(-60, 0, 60, 0);       //
line(0, 60, 0, -60);       // draw stationary axis lines
line(0, 0, -60, 0, 0, 60); //
strokeWeight(0); // PPP: STROKEWEIGHT VON 1 NACH 0
stroke(0, 150, 0);
noFill();
box(40);                  // draw stationary box


rotateX(rotx);  //
rotateY(roty);  // rotate drawing coordinates according to user input variables
rotateZ(rotz);  //
strokeWeight(0);
stroke(255);
line(10, 0, 10, 0);       //PPPP ALL PLACES WITH 50 USED TO BE 150
line(0, 10, 0, -10);       // draw the rotating axis lines
line(0, 0, -10, 0, 0, 10); //
strokeWeight(4);
stroke(57, 255, 20);
noFill();
box(100,60,350); // draw rotating red box PPPPP: CHANGED FROM 140!!!

} }

void serialEvent(Serial myPort) {

// read the serial buffer:2 String myString = myPort.readStringUntil(linefeed);

// if you got any bytes other than the linefeed: if (myString != null) {

myString = trim(myString);

// split the string at the commas
// and convert the sections into integers:

pSensors = sensors;
sensors = float(split(myString, ','));

// print out the values you got:

for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
  print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}

// add a linefeed after all the sensor values are printed:
println();

} }


Processing AnalogRead

$
0
0

Hi, I can't read two different analog pins (two sensors) using processing. I can only read what comes from the COM port but I can't read from specific analog input pins for example (A0 and A1). I'm using arduino mega. Is possible to read from two different pins in Processing? How to do? Thank you

send data over internet to arduino

$
0
0

Hey everyone,

I'm working on a project for my university which involves building a remote controlled robot which works over wifi. Now I have everything working in my control program, except it can only send data over COM ports, so unless I connect the arduino through a usb cable it does not work. Now my question is how it would be possible for me to use processing to send the data to an ip address. The actual data being sent is a byte which looks like #0000000.

Hopefully you guys can help, thanks in advance!

Drawing a graph with the Line command

$
0
0

I'm trying to draw a graph, given in this simple tutorial: https://www.arduino.cc/en/Tutorial/Graph. I'm using the Arduino IDE 1.6.5 and Processing 3.0b5. Still NO graph appears. When I insert "println" commands in the Processing-code, I can tell that Processing is recieving data, and has the correct coordinates in order to draw the lines, but no lines appear. It is as though the Line-command is out of function in the void serialEvent. Please help.

Problem reading a RFID reader

$
0
0

Hi there,

I have this SparkFun RFID Starter Kit (https://www.sparkfun.com/products/13198?_ga=1.242738306.1686357739.1444361942), I followed the steps in the HookUp guide (https://learn.sparkfun.com/tutorials/sparkfun-rfid-starter-kit-hookup-guide?_ga=1.177165093.1278763627.1444260091), and It seems that is working fine, although I'm not getting the same reads as the guide.

Example: The guide shows this screenshot of the Arduino serial port while reading the card:

And I get this value:

If I swipe the card another time, I get this reading:

What are those little squares? I guess is some kind of character but I don't know which, or why is there.

Any ideas?

I am also trying this RFID reader in Processing. To change a message in the screen if someone swipes the card.

Initial screen:

After one read:

The text "saldo en 0" should have changed to "deposito $50"", but it shouldn't.

Any ideas?

Thanks!!

The code:

import processing.serial.*;
Serial myPort;
String inString = "texto inicial";
String mensaje;

void setup () {
  size(400, 300);        
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
  background(0);
}
void draw () {
  background(0);
  String s = inString;
  String comparador = "4500B8C02A17";
  textSize(24);
  fill(100);
  text(s, height/3, width/3); 

  if (comparador.equals(s) == true) {
    mensaje = "deposito $50";
  } else {
    mensaje = "saldo en 0";
  }
  text(mensaje, height/3, width/3+30);
}

void serialEvent (Serial myPort) {
  inString = myPort.readStringUntil('\n');
}

why this code works on Processing 1.51 and don't work on 3.0 ver.

$
0
0

I'm a newbie about Processing and I'm studying a book "Making Things Talk" 2nd edition. I would know where is the mistake in this code.

/* Serial String Reader Context: PROCESSING

Reads in a string of characters until it gets a linefeed (ASCII 10). Then converts the string into a number.

*/

import processing.serial.*;

Serial myPort; // the serial port float sensorValue = 0; // the value from the sensor float prevSensorValue = 0; // previous value from the sensor float lastXPos = 0; // previous horizontal position float lastYPos = 0; float xPos = 0; // horizontal position of the graph float yPos = 0; int lf = 10;

void setup() { size(400,300);

//list all the available serial ports printArray(Serial.list()); //println(Serial.list());

// I know that the first port in the serial list on my Mac is always my Arduino. // so I open Serial.list()[0]. myPort = new Serial(this,Serial.list()[3], 9600);

// read bytes into a buffer until you get a newline (ASCII10); myPort.bufferUntil(lf);

// Set initial background and smooth drawing: background(#543174); smooth(); }

void draw() { // nothing happens here }

void serialEvent (Serial myPort) { // get the ASCII string String inString = myPort.readStringUntil(lf);

if (inString != null) { //trim off any whitespace inString = trim(inString); // convert to an integer and map to the screen height sensorValue = float(inString); sensorValue = map(sensorValue, 0, 1023, 0, height);
drawGraph(prevSensorValue, sensorValue); // save the current value for the next time prevSensorValue=sensorValue; } }

void drawGraph(float prevValue, float currentValue) { // subtrack the values from the window height // so that higher numbers get drawn higher on the screen float yPos = (height -currentValue);
float lastYPos = (height -prevValue); // draw the line in a pretty color
stroke(#C7AFDE); //#C7AFDE line(lastXPos, lastYPos, xPos, yPos); // at the edge of the screen, go back to the begining: if (xPos >= width) { xPos = 0; lastXPos = 0; background(#543174); } else { // increment the horizontal position:
// save the current graph position // for next time: lastXPos = xPos; xPos++; } }

Reading data from txt file

$
0
0

Hi all,

We are trying to read the data in the .txt file which include

1   0   0   0   1549,01050
1   0   0   0   1549,08360
1   0   0   0   1549,07956
1   0   0   0   1549,07956
1   0   0   0   1549,07552
1   0   0   0   1549,03956
1   0   0   0   1549,07956
1   0   0   0   1549,08158
1   0   0   0   1549,08360
1   0   0   0   1549,07956
1   0   0   0   1549,04148
1   0   0   0   1549,07350
1   0   0   0   1549,02442

such values in it.

After doing that, what we would like to do is to compare the values just in the 5th column with 1549.05 one by one. If any decimal number in the 5th column is bigger than 1549.05, then in the processing, we may create a array or string or something(Since I am new in Processing and Arduino, I may not know true term ) like that which just includes 1s or 0s.

for example

arry=[]

for i=1

1549.05>1549,01050 => make that; arry=[1]

for i=2

1549.05<1549,08360 => make that; arry=[1 0] . . .

The following code is what I found in the web and try to modify it for my purpose.

After obtaining such an array which I called above "arry", the Processing code will send that data to Arduino and it will turn on or off the pin13 depending on which number(0 or 1) is being sent from Processing to Arduino.

The Processing code that we try to modify

import processing.serial.*; 
import java.io.*; 
int mySwitch=0; 
int counter=0;
int i=0;
String [] subtext;
Serial myPort; 

void setup() { 
  mySwitch=1; 
  myPort = new Serial(this, "COM12", 9600); 
  myPort.bufferUntil('\n');
} 

void draw() { 
  if (mySwitch>0) { 
    readData("C:/Python32/BridgeStrain.txt"); 
    mySwitch=0;
  } 
  if (counter<subtext.length) { 
    myPort.write(subtext[counter]); 
    delay(500); 
    myPort.write('0'); 
    delay(100); 
    counter++;
  } else { 
    delay(5000); 
    mySwitch=1;
  }
} 

void readData(String myFileName) { 

  File file=new File(myFileName); 
  BufferedReader br=null; 

  try { 
    br=new BufferedReader(new FileReader(file)); 
    String text=null;
        while ((text=br.readLine())!=null) { 
      subtext = splitTokens(text, ",");
    }
  }
  catch(FileNotFoundException e) { 
    e.printStackTrace();
  }
  catch(IOException e) { 
    e.printStackTrace();
  }
  finally { 
    try { 
      if (br != null) { 
        br.close();
      }
    } 
    catch (IOException e) { 
      e.printStackTrace();
    }
  }
} 

Arduino Code

int outPin = 13;          //define outpin 
float signal; 
void setup() { 
  Serial.begin(9600); 
  pinMode(outPin,OUTPUT); //set output pin 
} 

void loop() { 
    while (Serial.available()>0) { 
      signal = Serial.parseFloat(); 

      if(signal>1){ 
        digitalWrite(outPin, LOW); 
      } 
      else{ 
        digitalWrite(outPin,HIGH); 
      } 
    } 
 } 

Your valuable comments for solving our problem are very appreciated.

Bests, Çağdaş

Read only a serial data (among many )

$
0
0

I have a ultrasonic sense and a MPU 6050 (aaccelerometer), and i am using teapot. My problem is that on the monitor serie, it shows the ultrasonic and accelerometer printings. And i only want to read with processing the accelerometer's data, that is reading only one line of the arduino's serial data. Not all of the lines Sorry for my english. I need it quickly, thanks!


Problem to receive serial data from processing to arduino duemilanove

$
0
0

Hi all, Does anyone has information to receive data commnunication from processing to "arduino duemilanove" by sending "0" or "1" byte through serial ? I've received nothing when communicate from serial to arduino and need someone to further guide me. Those reference I took from websites "https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing"

My coding in processing:

import processing.serial.*; Serial myport;

void setup(){

  String portname = Serial.list()[0]; 
  myport = new Serial(this,portname,9600);

}

void draw(){

  if (myport.available() > 0 )
  {
         myport.write("1");
         println("Print 1 to arduino Now");
  }

}

My coding in arduino : (I'd tried to monitor incoming byte from process in serial monitor)

int incomingByte = 0 ;

void setup() {

Serial.begin(9600); 

}

void loop() {

if (Serial.available() > 0 )
{
  incomingByte = Serial.read();
  Serial.print("check :");
  Serial.println(incomingByte,DEC);
}

}

The situation is weird where It show nothing happened and returned empty in output once I opened serial monitor to check out. I've managed to pluged in to power arduino(First) and click to run processing(second). How i could possible to receive "1" from processing to arduino through serial monitor?

Hopw someone could guide me in further, Thanks.

code for laserarp.... how can i use minim library????

$
0
0

hi everybody, i'm learning to use arduino and my actually project is for university.... I've built a laserarp with seven laser.... But for the presentation i need to play not from my computer, and i want also to have different 'instrument to play'(like note from piano and note from guitar or drum...)... i've written a code based on transmission from serial of arduino to processing and whith minim i've tryed to play sound, but i don't have idea of how set file to play, or how to set speaker or anything that depend from minim library..... may you help me? thank you!!

Library Mangement System using RFID Arduino

$
0
0

Hello , I am naman gautam. Sir i want to develop a library mangement system for my college library but i am having issues with building database. how can i use processing with SQL and then connect it to Arduino. I just want to know how could i start with developing this using processing software though and can connect this to Arduino. I had once connect arduino to processing and make a basic switch program so i have some basic knowledge about processing. I have already worked with Arduino so i am having problem with processing and SQL.

Measuring Plant, Visualizing values with a Graph in Processing

$
0
0

Hi ! I'm trying to measure the tiny changes of conductivity in a plant when it interacts with its surrounding. I want to visualize that with a graph in Processing. I have this code below. It tries to average the values out. Every time I want to run it, it just does there is a little bit of green line and then it stops. The is not a graph. But the values I am measuring with the Arduino are coming in without any problem.

Who can maybe help me further? Thank you :)

 import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph
float averY = 10;      // average input level
float averX = averY;        // mapped averY
float mediumY = averY;  // shorter average
float mediumX = 0;
float minVal = 0;
float maxVal = 1100; 
int baudRate = 115200;
int avFactor = 2000;
int medFactor = 200;
int stressed;
int touched;
int relaxed;
float inByte;
int frameNr = 1;


void setup () {
  size(1200, 800);        
  myPort = new Serial(this, Serial.list()[5], baudRate);
  myPort.bufferUntil('\n');
  frameRate(600);
  background(0);
  // show values
  textSize(20);
  fill(255);
  text(maxVal, 10, 30);
  text(minVal, 10, height-30);
}
void draw () {
  // everything happens in the serialEvent()
}

void serialEvent (Serial myPort) {
  // delay(50);
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);
    inByte = float(inString)/2; 

    if (inByte > 0 && inByte < 500) {

      //println("   ");
      //println(inByte);

      // now average this out

      if (frameNr < 200) {
        //  averY = ((avFactor - 1)*averY + inByte)/100;
        //  mediumY = averY;
        //  } else if (xPos < 1000) {
        averY = ((frameNr - 1)*averY + inByte)/frameNr;
        mediumY = averY;
      } else {
        averY = ((avFactor - 1)*averY + inByte)/avFactor;
        mediumY = ((medFactor - 1)*mediumY + inByte)/medFactor;
      }

      // draw pure [blue]
      // stroke(0, 0, 255);
      // point(xPos, height - round(inByte2));

      // draw average [white]
      averX = map(averY, minVal, maxVal, 0, height);
      stroke(255, 255, 255);
      point(xPos, height - round(averX));
      //println(averY);

      //draw medium [green]
      mediumX = map(mediumY, minVal, maxVal, 0, height);
      stroke(0, 225, 0);
      point(xPos, height - round(mediumX));
      println(mediumY);


      // draw short [red]
      // shortX = map(shortY, minVal, maxVal, 0, height);
      // stroke(255, 0, 0);
      // point(xPos, height - round(shortX));

      // check if mediumY is high

      if (mediumY > 1.1*averY) {  // TOUCHED!
        touched++;
        if (touched > 20) {
          stressed = 0;
          relaxed = 0;
          fill(255, 0, 0, 255);
          noStroke();
          rect(0, 0, width, 20);
        }
      } else if (abs(mediumY-averY) > 0.05*averY) {  // STRESSED!
        stressed++;
        if (stressed > 100) {
          touched = 0;
          relaxed = 0;
          fill(0, 255, 0, 255);
          noStroke();
          rect(0, 0, width, 20);
        }
      } else {
        relaxed++;
        if (relaxed > 200) {
          touched = 0;
          stressed = 0;
          fill(0, 255);
          noStroke();
          rect(0, 0, width, 20);
        }
      }
      // println(stressed);

      if (xPos >= width) {

        // black overlay
        xPos = 0;
        fill(0, 80);
        noStroke();
        rect(0, 0, width, height);
      } else {
        xPos++;
      }
      frameNr++;
    }
  }
}![Plantreader](http://forum.processing.org/two/uploads/imageupload/674/F22PT6EUWBZF.png "Plantreader")

Plantreader Kopie

mapping error - arduino, very basic

$
0
0

Hey yall - firstly thanks for any help.

I am trying to run the very basic "graph" tutorial off of an arduino. (https://www.arduino.cc/en/Tutorial/Graph). I have a simple circuit with a potentiometer.

When I run this processing code, I get the following error:

map(NaN, 0, 1023, 0, 300) called, which returns NaN (not a number)

Weird. But if I type "println(inByte)" after my map line, the console shows me changing potentiometer values just fine. No error. Also, I should say the pop-out window which is supposed to graph my moving values is black, and never shows any sort of graph. Thanks again for all your help -

Arduino+Processing Problem: ArrayIndexOutOfBounds

$
0
0

Hi Everyone, i've been working on a little program combining arduino and processing aiming at generating visuals from movement ( gyroscope + vibration sensor).

So far I tested both the gyroscope and the vibration sensor separately and it worked just fine. Since I've tried to combine them i've been getting this error message: ArrayIndexOutOfBoundsException: 1 and the line 53: float roty = (sensors[1]*10); is highlighted at the same time

I assume there is a problem with myString content, or I guess with the string access and my sensors declaration but I can't figure out what to do. I've been learning code for a very short time, please have mercy on my inaccuracies ^^
(i'm french so comments are mostly in french,let me know if you need me to explain myself) Thank you so much for your help !!!

    import glitchP5.*; //import Glitch P5
    String portName = "/dev/cu.usbmodem1421"; 
    import processing.serial.*;
    String serial; 
    Serial myPort;
    int linefeed = 10; 
    int numSensors = 3; 
    float[] sensors;
    float[] pSensors;
    float bornexinf=0; 
    float bornexsup=0;
    float borneyinf=0; 
    float borneysup=0; 
    float rotxold=0; 
    float rotyold=0; 
    // vibration
    int end = 10;    //Le nombre 10 en ASCII pour linefeed marquant la fin du serial.println
    GlitchP5 glitchP5; // declare an instance of GlitchP5. only one is needed
    int j=0; //variable d'incrémentation carré dans carré
    int max=1; //nombre d'itération, soit le nb de carrés dans le carré
    int longueur=10; // longueur du carré 
    int largeur=10; //largeur du carré
    float value=0; //variable pour la rotation
    float mouseXold=displayWidth/2;
    float mouseYold=displayHeight/2;

    void setup() {

     size(displayWidth, displayHeight);
     background (255);
     smooth();

      myPort = new Serial(this, portName, 9600);
      myPort.bufferUntil(linefeed);
      serial = myPort.readStringUntil(end); // fonction qui lit la chaine de caractères depuis le port série jusqu'à println et ensuite assigne string à notre variable qui appelle serial
      serial = null; // initialisation de serial
     glitchP5 = new GlitchP5(this);
    }


    void draw() {

      while (myPort.available() > 0) { //tant qu'il n'y a pas de données provenant du port on lit l'entrée série
        serial = myPort.readStringUntil(end);
      }
        if (serial != null) {  
          String[] a = split(serial, ','); //on créé un tableau qui définit une chaine séparée par des virgules. 
          println(a[0]); //on affiche la première valeur du tableau
        }

      if((pSensors != null)&&(sensors != null)) { 
        float  rotx = (sensors[0]*10);
        float  roty = (sensors[1]*10);
        float  rotz = (sensors[2]*PI)/180;

    strokeWeight(1);
    noFill(); 
    stroke(random(255),random(255),random(255));
    translate(500,150);
    rectMode(CENTER);


    for(j=0;j<max;j++){
        longueur=longueur+1; 
        largeur=largeur+1; 
        translate(width/2, height/2);
        rotate(value);
        translate(-width/2, -height/2);
        rect(rotx,roty,longueur,largeur); 
        redraw();
        bornexinf=rotxold-10; 
        bornexsup=rotxold+10;
        borneyinf=rotyold-10; 
        borneysup=rotyold+10; 
        if(bornexinf>rotx || rotx>bornexsup || borneyinf>roty || roty>borneysup){
        longueur=5;
        largeur=5;
        }
        rotxold=rotx;
        rotyold=roty;
    }
      }
     glitchP5.run();
    }


    void serialEvent(Serial myPort) {


      String myString = myPort.readStringUntil(linefeed);
      if (myString != null) {
              myString = trim(myString);
              pSensors = sensors;
              sensors = float(split(myString, ','));

                     for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
                     print("Sensor" + sensorNum + ": " + sensors[sensorNum] + "\t");
        }
        println();
      }
    }

    void mousePressed() //===> Will be triggered by the vibration sensor : if =0 do nothing; if =1 glitch; //
    {
     glitchP5.glitch(mouseX, mouseY, 200, 400, 200, 60, 120, 10.0f, 20, 1);
    }

Make a photo crumble away when extra light falls on a LDR

$
0
0

Hi, For a couple of days now I have been trying to make a photo crumble away when I shine with a flashlight on a LDR. Both my Arduino code and Processing code work seperately, and I have established a handshake between those two. However, I don't know how to make something happen when the LDR messures a certain value. Does anyone know how to do this?

Thanks in advance!


How to avoid multiple keypresses from Fruit Piano sensors (Arduino USB HID)

$
0
0

I'm using Capacitive Sensors to measure input from fruit to trigger events in Processing (like a sound, or in this case a video). I don't want to delay the Arduino program, so it keeps scanning for input. The Arduino sens keypresses (as a USB HID device) to the pc, so I can detect keypresses in Processing. The problem is that often the Arduino is scanning so fast that it sends multiple Keypresses, so the video keeps triggering.

I want to solve this in Processing, so that I don't have to use a delay in the Arduino code. My question is, how do I integrate this type of code:

int sX, sY, sT;

void setup(){
  size(200,200);
}

void draw(){
  background(0);
  if( mousePressed ){
    sX = mouseX;
    sY = mouseY;
    sT = millis() + 2000;
  }
  if( millis() > sT && millis() < sT + 2000 ){
    fill(255,0,0);
    rect(sX-5, sY-5, 10, 10);
  }
}

into this:

  import processing.video.*;


int maxmyMovies = 5; 
int myMoviesIndex = 0; 
Movie[] myMovies = new Movie[maxmyMovies];

void setup() {

  size(1280, 720);
  for (int i = 0; i < myMovies.length; i ++ ) {
    myMovies[i] = new Movie(this, i + ".mp4");
    myMovies[i].loop();
  }
}

void movieEvent(Movie myMovies) {

  myMovies.read();
}

void draw() {
  image(myMovies[myMoviesIndex], 0, 0, 1280, 720); // Displaying one image
}

void keyPressed() {

  if (key=='a') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 1;
    myMovies[myMoviesIndex].play();
  } 
  if (key=='b') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 2;
    myMovies[myMoviesIndex].play();
  } 
  if (key=='c') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 3;
    myMovies[myMoviesIndex].play();
  } 
  if (key=='d') {
    myMovies[myMoviesIndex].pause();
    myMovies[myMoviesIndex].jump(0.0);
    myMoviesIndex = 4;
    myMovies[myMoviesIndex].play();
  }
}

I have to scan for almost the entire alphabet, so the code is getting very messy. Is there also a way of simplifying this? Thanks in advance for your help.

I can't get processing to respond on my arduino input

$
0
0

Hello, For a project I'm trying to make a game with processing and arduino. I'm making a game where you can move a basketball hoop to the left and right off the screen to catch falling basketballs. I'm trying to get the hoop to move to the right when the button is pressed and to the left when it isn't. For my arduino i'm using the 'button' code from the examples library.

My problem is that the hoop only moves to the left and doesn't move to the right when I press the button. Can somebody please see what I'm doing wrong?

my processing code is as follows:

///////////////////////////////////////////////////////////////////////

import processing.serial.*;
import cc.arduino.*;

Arduino arduino;


int buttonPin = 2;

int buttonState = 0;

int Xbas = 0;  // X coördinate for basket



void setup() {
  size(1350, 900);
  smooth();
  arduino = new Arduino(this, Arduino.list()[0], 100);
  arduino.pinMode(buttonState, Arduino.INPUT);
}

void Basket (int x, int y) {
  background(100);
  strokeWeight(1);
  pushMatrix();
  translate(width/2, height);
  for (int i = Xbas - 100; i <= Xbas + 40; i += 20) {
    line(i, -150, i + 30, -10);
  }
  for (int i = Xbas - 40; i <= Xbas + 100; i += 20) {
    line(i, -150, i - 30, - 10);
  }
  line(Xbas + 60, - 150, Xbas + 80, - 70);
  line(Xbas + 80, - 150, Xbas + 90, - 110);
  line(Xbas - 60, - 150, Xbas - 80, - 70);
  line(Xbas - 80, - 150, Xbas - 90, - 110);
  fill(#CE3419);
  ellipse(Xbas, -150, 200, 30);
  fill(100);
  ellipse(Xbas, -150, 130, 10);
  popMatrix();
}


void draw() {

  Basket (0, 0);


  if (arduino.digitalRead(buttonState) == Arduino.LOW) {
    Xbas += 2;
  } else if (arduino.digitalRead(buttonState) == Arduino.HIGH) {
    Xbas -= 2;
  }
}

//////////////////////////////////////////////////////////////////

Hello , Im stuck in something with my project (red eye)

$
0
0

Hello everyone, my project deals with the prevention of drunk driving and I write code to extract an image red color came from the eye (a symptom of alcohol on the eyes), I was able to display an image and communicate with the Arduino, but I need a way to image the code tell me if there are red eye or not. If anyone can help I'll be very happy! Thank you

Arduino input to move object when button is pressed

$
0
0

Hello,

For a project I'm trying to make a game with processing and arduino. I'm making a game where you can move a basketball hoop to the left and right off the screen to catch falling basketballs. I'm trying to get the hoop to move to the right when the button is pressed and to the left when it isn't. For my arduino i'm using the 'button' code from the examples library.

My problem is that the hoop only moves to the left and doesn't move to the right when I press the button. Can somebody please see what I'm doing wrong?

my processing code is as follows:

///////////////////////////////////////////////////////////////////////

import processing.serial.*;
import cc.arduino.*;

Arduino arduino;


int buttonPin = 2;

int buttonState = 0;

int Xbas = 0;  // X coördinate for basket



void setup() {
  size(1350, 900);
  smooth();
  arduino = new Arduino(this, Arduino.list()[0], 100);
  arduino.pinMode(buttonState, Arduino.INPUT);
}

void Basket (int x, int y) {
  background(100);
  strokeWeight(1);
  pushMatrix();
  translate(width/2, height);
  for (int i = Xbas - 100; i <= Xbas + 40; i += 20) {
    line(i, -150, i + 30, -10);
  }
  for (int i = Xbas - 40; i <= Xbas + 100; i += 20) {
    line(i, -150, i - 30, - 10);
  }
  line(Xbas + 60, - 150, Xbas + 80, - 70);
  line(Xbas + 80, - 150, Xbas + 90, - 110);
  line(Xbas - 60, - 150, Xbas - 80, - 70);
  line(Xbas - 80, - 150, Xbas - 90, - 110);
  fill(#CE3419);
  ellipse(Xbas, -150, 200, 30);
  fill(100);
  ellipse(Xbas, -150, 130, 10);
  popMatrix();
}


void draw() {

  Basket (0, 0);


  if (arduino.digitalRead(buttonState) == Arduino.LOW) {
    Xbas += 2;
  } else if (arduino.digitalRead(buttonState) == Arduino.HIGH) {
    Xbas -= 2;
  }
}

//////////////////////////////////////////////////////////////////

Problem Using two Arduino and a Class...

$
0
0

Hello everyone, So I am trying to make this "light Bike" kind of game, where a point moves (according to values sent by 2 different arduinos) while leaving a trace behind itself, and the point is to stay the longest possible while not recrossing the line... Now I defined this point in a class, but can't seem to associate the values coming in from arduino with it properly... Anyone have any ideas what might do the trick? Thanks!

By the way here is my code:

1 2 3 4 5

And the class...

Class 1 Class 2

Thank you for Any Help you can give!!!

Viewing all 747 articles
Browse latest View live