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

Shuffle mode video's

$
0
0

Hello everyone,

In short: My current project involves a arduino Uno and processing, PIR sensor sends a signal when a person walks past the sensor and a movie starts playing. So far so good, the code works perfecly but the problem i'm having is that we want multible movies playing in shufflemode. So when the PIR sensor is triggerd again processing start a differend movie. This is the code so far: import processing.video.*; import processing.serial.*; //importeer Serial library

Movie myMovie; boolean MoviePause = true; String Sensor; Serial port; String serial; // nieuwe string 'serial' int end = 10; // 10 is ASCII voor linefeed (einde van serial.println)

void setup() { fullScreen(); background(0); noStroke(); fill(102); Sensor="0"; port = new Serial(this, Serial.list()[0], 9600); // baudrate (snelheid) moet hetzelfde zijn als op de Arduino port.clear(); // serieele poort schoonmaken zodat er geen zooi in zit serial = port.readStringUntil(end); // lees poort totdat er een linefeed zit serial = null; background(0); myMovie = new Movie(this, "F:\Droombus.mp4"); //hier natuurlijk je eigen verwijzing naar film zetten myMovie.loop(); //film in een lus zetten, want stoppen betekent niet meer kunnen starten (althans, zonder hem helemaal opnieuw aan te maken) }

void draw() { background(255); image(myMovie, 0, 0); while (port.available() > 0) { //zoalng er data op de poort komt, uitlezen en opslaan serial = port.readStringUntil(end); } if (serial != null) { //data gevonden String[] a = split(serial, ','); //data komt binnen, gescheiden door komma's Sensor = (a[0]); Sensor = trim(Sensor); println(Sensor); }

if (myMovie.time() == myMovie.duration()){ //einde van de film bereikt. println("einde filmpje"); myMovie.pause(); //dan op pauze zetten. Niet stoppen dus!! MoviePause=true; //aangeven dat de film op pauze staat } if ((Sensor.equals("1") == true) & MoviePause==true){ //als de sensor weer 1 is (dus beweging) EN de film is afgelopen println("Sensor check"); MoviePause=false; myMovie.play(); //dan opnieuw verder afspelen (want staat in een lus) } }

void movieEvent(Movie m) { m.read(); }

Please can someone help us to fix the code we're kinda stuck on this problem

Thanks.


Movie's in code

$
0
0

Hello everyone,

In short: My current project involves a arduino Uno and processing, PIR sensor sends a signal when a person walks past the sensor and a movie starts playing. So far so good, the code works perfecly but the problem i'm having is that we want multible movies playing in shufflemode. So when the PIR sensor is triggerd again processing start a differend movie. This is the code so far:

import processing.video.*;
import processing.serial.*; //importeer Serial library

Movie myMovie;
boolean MoviePause = true;
String Sensor;
Serial port;
String serial;   // nieuwe string 'serial'
int end = 10;    // 10 is ASCII voor linefeed (einde van serial.println)

void setup() {
  fullScreen();
  background(0);
  noStroke();
  fill(102);
  Sensor="0";
  port = new Serial(this, Serial.list()[0], 9600); // baudrate (snelheid) moet hetzelfde zijn als op de Arduino
  port.clear();  // serieele poort schoonmaken zodat er geen zooi in zit
  serial = port.readStringUntil(end); // lees poort totdat er een linefeed zit
  serial = null;
  background(0);
  myMovie = new Movie(this, "F:\\Droombus.mp4"); //hier natuurlijk je eigen verwijzing naar film zetten
  myMovie.loop();  //film in een lus zetten, want stoppen betekent niet meer kunnen starten (althans, zonder hem helemaal opnieuw aan te maken)
}

void draw() {
  background(255);
  image(myMovie, 0, 0);
    while (port.available() > 0) { //zoalng er data op de poort komt, uitlezen en opslaan
    serial = port.readStringUntil(end);
  }
  if (serial != null) {  //data gevonden
      String[] a = split(serial, ',');  //data komt binnen, gescheiden door komma's
      Sensor = (a[0]);
      Sensor = trim(Sensor);
      println(Sensor);
  }

  if (myMovie.time() == myMovie.duration()){  //einde van de film bereikt.
    println("einde filmpje");
    myMovie.pause();    //dan op pauze zetten. Niet stoppen dus!!
    MoviePause=true;    //aangeven dat de film op pauze staat
  }
  if ((Sensor.equals("1") == true) & MoviePause==true){  //als de sensor weer 1 is (dus beweging) EN de film is afgelopen
    println("Sensor check");
    MoviePause=false;
    myMovie.play();                                      //dan opnieuw verder afspelen (want staat in een lus)
  }
}

void movieEvent(Movie m) {
  m.read();
}

Please can someone help us to fix the code we're kinda stuck on this problem

Thanks.

Question about G4P

$
0
0

I'm a beginner~~~~ I use G4P to design a GUI interface to control my Arduino(like a filter, to handle the parameter from my sensor and deliver it to computer). 屏幕快照 2016-03-09 下午4.56.06

Something like this, people can input the sampling frequency they want and adjust the level of filter. But the question comes......

This is the Code from G4P(automatic programmed) I don't know how to use this and get my parameter or the address from the knob,so i can not connect this with Arduino. For example, people input the 100 sec, i can give this "100" to Arduino and in the right people can adjust the level, from min to max.

public void knob4_turn1(GKnob source, GEvent event) { //CODE:Filter:944770:
println("knob4 - GKnob >> GEvent." + event + " @ " + millis());
} //CODE:Filter:944770:

public void textfield3_change1(GTextField source, GEvent event) { //CODE:textfield3:900916:
println("textfield3 - GTextField >> GEvent." + event + " @ " + millis());
} //CODE:textfield3:900916:

public void button1_click1(GButton source, GEvent event) { //CODE:button1:684909:
println("button1 - GButton >> GEvent." + event + " @ " + millis());
} //CODE:button1:684909:



// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
Filter = new GKnob(this, 272, 100, 166, 188, 0.8);
Filter.setTurnRange(210, 330);
Filter.setTurnMode(GKnob.CTRL_ANGULAR);
Filter.setShowArcOnly(true);
Filter.setOverArcOnly(false);
Filter.setIncludeOverBezel(false);
Filter.setShowTrack(true);
Filter.setLimits(0.0, 0.0, 1.0);
Filter.setNbrTicks(10);
Filter.setShowTicks(true);
Filter.setOpaque(false);
Filter.addEventHandler(this, "knob4_turn1");
textfield3 = new GTextField(this, 70, 126, 62, 27, G4P.SCROLLBARS_NONE);
textfield3.setOpaque(true);
textfield3.addEventHandler(this, "textfield3_change1");
label2 = new GLabel(this, 256, 134, 32, 23);
label2.setText("min");
label2.setOpaque(false);
label1 = new GLabel(this, 425, 136, 33, 21);
label1.setText("max");
label1.setOpaque(false);
label3 = new GLabel(this, 129, 127, 33, 22);
label3.setText("Sec");
label3.setOpaque(false);
button1 = new GButton(this, 166, 126, 30, 24);
button1.setText("OK");
button1.setLocalColorScheme(GCScheme.CYAN_SCHEME);
button1.addEventHandler(this, "button1_click1");
}

// Variable declarations
// autogenerated do not edit
GKnob Filter;
GTextField textfield3;
GLabel label2;
GLabel label1;
GLabel label3;
GButton button1;

// Need G4P library
import g4p_controls.;
import processing.serial.
;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
PImage img;
int logoX = 310, logoY = 15;
PFont f;
int wordStartX = 120, wordStartY = 230;
int wordStopX = 293, wordStopY = 230;
int wordAbtastX = 70, wordAbtastY = 100;
int wordFilterX = 330, wordFilterY = 100;
int startX = 180, startY = 223;
int stopX = 350, stopY = 223;
int circleSize = 20;
color startColor = color(0, 190, 15);
color stopColor = color(230, 10, 0);
color pressColor = color(100);
boolean startOver = false, stopOver = false;

public void setup(){
size(500, 300);
createGUI();
customGUI();
f = loadFont("Calibri-48.vlw");
img = loadImage("logo.jpg");
smooth();
noStroke();
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 9600);
// Place your setup code here

}

public void draw(){
background(255);
image(img, logoX, logoY, img.width/2, img.height/2);
update(mouseX, mouseY);

if (mousePressed && startOver)
{fill(pressColor);}
else
{fill(startColor);}
ellipse(startX, startY, circleSize, circleSize);

if (mousePressed && stopOver)
{fill(pressColor);}
else
{fill(stopColor);}
ellipse(stopX, stopY, circleSize, circleSize);

textFont(f, 20);
fill(0,65,115);
text("Start", wordStartX, wordStartY);
text("Stop", wordStopX, wordStopY);
text("Abtastfrequenz", wordAbtastX, wordAbtastY);
text("Filter", wordFilterX, wordFilterY);
}

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){

}
void update(int x, int y) {
if ( overStart(startX, startY, circleSize) ) {
startOver = true;
stopOver = false;
} else if ( overStop(stopX, stopY, circleSize) ) {
stopOver = true;
startOver = false;
} else {
startOver = stopOver = false;
}
}

boolean overStart(int x, int y, int diameter) {
float disX = x - mouseX;
float disY = y - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}

boolean overStop(int x, int y, int diameter) {
float disX = x - mouseX;
float disY = y - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}`

Help~~~~~

Receiving data from BLE enabled Arduino

$
0
0

Hello. I am doing an Arduino project and currently send data from Arduino to a Processing App via a serial connection, which works as expected. However I want to send the data over Bluetooth Low Energy (BLE), which I have implemented on the Arduino end. I would be very thankful if you could point me to a resource where I can find out how to read data via BLE in Processing, because this is the first time I am using it.

Question about Excel

$
0
0

I want to put the parameter from arduino to the excel.

1.The XlsReader in the Homepage can not be used in the latest processing version,i put that in the library file, but dosen't work.Should i download the old version,or someone can help?

2.I also tried the other way, such like using the code from this web.

https://conorblack.wordpress.com/2014/03/23/export-import-processing-excel-xlsx/ But could someone show me some simple examples, to use this code.

Thx a lot~~

Why am I getting errors

$
0
0

I have been testing some code so that I can change it to use with my Arduino. However, it isn't working. it says that the val variable and myport variable aren't used and can't be found when running it? Would anyone be able to help me correct it?

import processing.serial.*;

void setup() { Serial myPort; // Create object from Serial class String val; // Data received from the serial port

// I know that the first port in the serial list on my mac // is Serial.list()[0]. // On Windows machines, this generally opens COM1. // Open whatever port is the one you're using. String portName = Serial.list()[3]; //change the 0 to a 1 or 2 etc. to match your port myPort = new Serial(this, portName, 115200); }

void draw() { if (myPort.available() > 0) { // If data is available, val = myPort.readStringUntil('\n'); // read it and store it in val } println(val); //print it out in the console }

Shuffle mode mymovie

$
0
0

Hello everyone,

In short: My current project involves a arduino Uno and processing, PIR sensor sends a signal when a person walks past the sensor and a movie starts playing. So far so good, the code works perfecly but the problem i'm having is that we want multible movies playing in shufflemode. So when the PIR sensor is triggerd again processing start a differend movie. This is the code so far: import processing.video.*; import processing.serial.*; //importeer Serial library

Movie myMovie;
boolean MoviePause = true;
String Sensor;
Serial port;
String serial;   // nieuwe string 'serial'
int end = 10;    // 10 is ASCII voor linefeed (einde van serial.println)

void setup() {
  fullScreen();
  background(0);
  noStroke();
  fill(102);
  Sensor="0";
  port = new Serial(this, Serial.list()[0], 9600); // baudrate (snelheid) moet hetzelfde zijn als op de Arduino
  port.clear();  // serieele poort schoonmaken zodat er geen zooi in zit
  serial = port.readStringUntil(end); // lees poort totdat er een linefeed zit
  serial = null;
  background(0);
  myMovie = new Movie(this, "F:\\Droombus.mp4"); //hier natuurlijk je eigen verwijzing naar film zetten
  myMovie.loop();  //film in een lus zetten, want stoppen betekent niet meer kunnen starten (althans, zonder hem helemaal opnieuw aan te maken)
}

void draw() {
  background(255);
  image(myMovie, 0, 0);
    while (port.available() > 0) { //zoalng er data op de poort komt, uitlezen en opslaan
    serial = port.readStringUntil(end);
  }
  if (serial != null) {  //data gevonden
      String[] a = split(serial, ',');  //data komt binnen, gescheiden door komma's
      Sensor = (a[0]);
      Sensor = trim(Sensor);
      println(Sensor);
  }

  if (myMovie.time() == myMovie.duration()){  //einde van de film bereikt.
    println("einde filmpje");
    myMovie.pause();    //dan op pauze zetten. Niet stoppen dus!!
    MoviePause=true;    //aangeven dat de film op pauze staat
  }
  if ((Sensor.equals("1") == true) & MoviePause==true){  //als de sensor weer 1 is (dus beweging) EN de film is afgelopen
    println("Sensor check");
    MoviePause=false;
    myMovie.play();                                      //dan opnieuw verder afspelen (want staat in een lus)
  }
}

void movieEvent(Movie m) {
  m.read();
}

Please can someone help us to fix the code we're kinda stuck on this problem

Thanks.

Shuffle mode Movies

$
0
0

Hello everyone,

In short: My current project involves a arduino Uno and processing, PIR sensor sends a signal when a person walks past the sensor and a movie starts playing. So far so good, the code works perfecly but the problem i'm having is that we want multible movies playing in shufflemode. So when the PIR sensor is triggerd again processing start a differend movie. This is the code so far: import processing.video.*; import processing.serial.*; //importeer Serial library

Movie myMovie;
boolean MoviePause = true;
String Sensor;
Serial port;
String serial;   // nieuwe string 'serial'
int end = 10;    // 10 is ASCII voor linefeed (einde van serial.println)

void setup() {
  fullScreen();
  background(0);
  noStroke();
  fill(102);
  Sensor="0";
  port = new Serial(this, Serial.list()[0], 9600); // baudrate (snelheid) moet hetzelfde zijn als op de Arduino
  port.clear();  // serieele poort schoonmaken zodat er geen zooi in zit
  serial = port.readStringUntil(end); // lees poort totdat er een linefeed zit
  serial = null;
  background(0);
  myMovie = new Movie(this, "F:\\Droombus.mp4"); //hier natuurlijk je eigen verwijzing naar film zetten
  myMovie.loop();  //film in een lus zetten, want stoppen betekent niet meer kunnen starten (althans, zonder hem helemaal opnieuw aan te maken)
}

void draw() {
  background(255);
  image(myMovie, 0, 0);
    while (port.available() > 0) { //zoalng er data op de poort komt, uitlezen en opslaan
    serial = port.readStringUntil(end);
  }
  if (serial != null) {  //data gevonden
      String[] a = split(serial, ',');  //data komt binnen, gescheiden door komma's
      Sensor = (a[0]);
      Sensor = trim(Sensor);
      println(Sensor);
  }

  if (myMovie.time() == myMovie.duration()){  //einde van de film bereikt.
    println("einde filmpje");
    myMovie.pause();    //dan op pauze zetten. Niet stoppen dus!!
    MoviePause=true;    //aangeven dat de film op pauze staat
  }
  if ((Sensor.equals("1") == true) & MoviePause==true){  //als de sensor weer 1 is (dus beweging) EN de film is afgelopen
    println("Sensor check");
    MoviePause=false;
    myMovie.play();                                      //dan opnieuw verder afspelen (want staat in een lus)
  }
}

void movieEvent(Movie m) {
  m.read();
}

Please can someone help us to fix the code we're kinda stuck on this problem

Thanks.


image of 64x64 pixels converted to 0 and 1

$
0
0

Hello, please tell me how Black and white image of 64x64 pixels converted to 0 and 1 , and send for execution to the Arduino. On the Processing programming language. As a result of UNO must control three servo motors and paint marker. I understand English very bad , sorry. Where to begin? What libraries should I use? Perhaps there is an example of a sketch on Processing?

Thank you,

Changing video in Processing using a sensor and an Arduino

$
0
0

I'm currently in the middle of creating a book on which the content is projected down rather than printed on to the pages. This is because I want to incorporate media like video and animation in to the project.

I'm using an ultrasonic sensor to tell the Arduino if a page is turning or not. It sends out a signal which is displayed in the Serial Monitor as either PageTurn or NoPageTurn respectively. This is the Arduino code:

#define trigPin 12
#define echoPin 13

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

  if (distance >= 400 || distance <= 2){
    Serial.println("Out of range");
  }
  else if (distance >=3 && distance <=100){
    Serial.print(distance);
    Serial.println(" cm");
    Serial.println("PageTurn");
  }

   else {
    Serial.print(distance);
    Serial.println(" cm");
    Serial.println("NoPageTurn");
  }
  delay(2000);

}

The Arduino code is working perfectly. The serial port displays either PageTurn or NoPageTurn depending on whether not the page of the physical book is turned.

I want to bring this in to Processing but I am limited in knowledge on the subject. My aim is to use Processing to display video, but I can't get the video to display properly. This is my Processing code: import processing.video.*; Movie myMovie;

void setup() {
  size(200, 200);
  myMovie = new Movie(this, "ch1.mov");
  myMovie.play();
}

void draw() {
  image(myMovie, 0, 0);
}

void movieEvent(Movie m) {
  m.read();
}

Questions

  1. How do I make the video display through Processing?

  2. How can I use the sensor to change the video that's playing, when it displays "PageTurn" in the serial port in Arduino. The pages of the book are all .mov files, labelled ch1.mov - ch6.mov. When the page is turned, I want to change the video that's projected on to the page. This is done through Processing I assume, but I can't figure out how.

  3. Also, I'm going to need to display the video in full screen mode, in order for it to be projected properly. I'm considering using the GSVideo Library for this, but I don't know how to go about this.

  4. I come from a design background so all of this is new to me, if I should be using something other than Processing to do the video stuff please let me know.

Thanks for any help you can provide on the subject.

Processing+arduino and supersonic senson

How to send a gcode via button press

$
0
0

Hi,

I am very new to processing.

I am making a syringe pump following the instructions from MIT's open syringe pump. The pump is operated by pressing a push or pull button on processing sketch. The button press sends a gcode to Arduino.

http://fab.cba.mit.edu/classes/863.13/people/wildebeest/projects/final/index.html

However, I could not see these buttons (pull and push) shown in the webpage, when I run the program on my windows machine. Am I missing something? This project is very important for my research. Can somebody help me.

Link to the code is here. I flagged it as an issue in github, but no response so far. So I am posting here with a hope to get it working.

https://raw.githubusercontent.com/wgpatrick/opensyringepump/master/syringe_pump_gcode_DIY/syringe_pump_gcode_DIY.pde

Many thanks in advance

Individually read multiple serial values from Arduino?

$
0
0

I have the Arduino reading two pushbuttons and need Processing to display 2 differenty boxes depending on which button is pressed (display both boxes if they are both pressed, and neither if non are pressed). How can I tell processing to read and separate the different values coming from the arduino?

I'm pretty new with processing so it could be something simple I just don't know.

Thanks in advance

//Arduino code:

int switchPin = 4;
int switchPin2 = 5;

void setup() { pinMode(switchPin, INPUT);
pinMode(switchPin2, INPUT); Serial.begin(9600);
}

void loop() {

int switch1 = digitalRead(switchPin); int switch2 = digitalRead(switchPin2);

if( digitalRead(switchPin) ==HIGH) {
Serial.write('a');
Serial.print('a');

if( digitalRead(switchPin2) ==HIGH) {
Serial.write('b');

}

else { Serial.write('x'); }

delay(100);

}

need help for arduinoscope

$
0
0

i am doing arduinoscope .the program in the arduino works well.but when running processing program ,it shows error as

       **** the func id() does not exist****

can anybody suggest any help for this please??

arduino program:

/*
this goes on your arduino
for use with Processing example SimpleSerialArduinoscope

*/

// holds temp vals
int val;

void setup() {
  // set 2-12 digital pins to read mode
  for (int i=2;i<14;i++){
    pinMode(i, INPUT);
  }

  Serial.begin(115200);
}

void loop() {
  // read all analog ports, split by " "
  for (int i=0;i<6;i++){
    Serial.print(analogRead(i));
    Serial.print(" ");
  }

  // read all digital ports, split by " "
  for (int i=2;i<14;i++){
    Serial.print(digitalRead(i));
    Serial.print(" ");
  }

  // frame is marked by LF
  Serial.println();
}

processing:

/*
  This is a basic serial arduinoscope.

  (c) 2009 David Konsumer <david.konsumer@gmail.com>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
 */

/*

Serial data comes in, in the format

1 23 34 4 5 76
1 23 34 4 5 76
1 23 34 4 5 76
1 23 34 4 5 76

(space seperates pin=data, LF-seperated frame data)

*/

import arduinoscope.*;
import processing.serial.*;

// this example requires controlP5
// http://www.sojamo.de/libraries/controlP5/
import controlP5.*;


// how many scopes, you decide.
Oscilloscope[] scopes = new Oscilloscope[6];
Serial port;
ControlP5 controlP5;

PFont fontLarge;
PFont fontSmall;

int LINE_FEED=10;

int[] vals;

void setup() {
  size(800, 800, P2D);
  background(0);

  controlP5 = new ControlP5(this);

  // set these up under tools/create font, if they are not setup.
  fontLarge = loadFont("TrebuchetMS-20.vlw");
  fontSmall = loadFont("Uni0554-8.vlw");

  int[] dimv = new int[2];
  dimv[0] = width-130; // 130 margin for text
  dimv[1] = height/scopes.length;

  // setup vals from serial
  vals = new int[scopes.length];

  for (int i=0;i<scopes.length;i++){
    int[] posv = new int[2];
    posv[0]=0;
    posv[1]=dimv[1]*i;

    // random color, that will look nice and be visible
    scopes = new Oscilloscope(this, posv, dimv);
    scopes.setLine_color(color((int)random(255), (int)random(127)+127, 255));


    controlP5.addButton("pause",1,dimv[0]+10,posv[1]+10,32,20).setId(i);
    controlP5.addButton("logic",1,dimv[0]+52,posv[1]+10,29,20).setId(i+50);
    controlP5.addButton("save",1,dimv[0]+92,posv[1]+10,29,20).setId(i+100);
  }

  port = new Serial(this, Serial.list()[2], 115200);

  // clear and wait for linefeed
  port.clear();
  port.bufferUntil(LINE_FEED);
}

void draw()
{
  background(0);

  // int[] vals = getTestValuesSquare();
  // int[] vals = getTestValuesSin();

  for (int i=0;i<scopes.length;i++){
    // update and draw scopes

    scopes.addData(vals);
    scopes.draw();

    // conversion multiplier for voltage
    float multiplier = scopes.getMultiplier()/scopes.getResolution();

    // convert arduino vals to voltage
    float minval = scopes.getMinval() * multiplier;
    float maxval = scopes.getMaxval() * multiplier;
    int[] values = scopes.getValues();
    float pinval =  values[values.length-1] * multiplier;

    // add lines
    scopes.drawBounds();
    stroke(255);

    int[] pos = scopes.getPos();
    int[] dim = scopes.getDim();

    line(0, pos[1], width, pos[1]);

    // add labels
    fill(255);
    textFont(fontLarge);
    text(pinval, width-60, pos[1] + dim[1] - 10);

    textFont(fontSmall);
    text("min: " + minval, dim[0] + 10, pos[1] + 40);
    text("max: " + maxval, dim[0] + 10, pos[1] + 48);

    fill(scopes.getLine_color());
    text("pin: " + i, dim[0] + 10,pos[1] + dim[1] - 10);
  }

  // draw text seperator, based on first scope
  int[] dim = scopes[0].getDim();
  stroke(255);
  line(dim[0], 0, dim[0], height);

  // update buttons
  controlP5.draw();

}

// handles button clicks
void controlEvent(ControlEvent theEvent) {
  int id = theEvent.controller().id();

  // button families are in chunks of 50 to avoid collisions
  if (id < 50){
    scopes[id].setPause(!scopes[id].isPause());
  }else if (id < 100){
    scopes[id-50].setLogicMode(!scopes[id-50].isLogicMode());
  }else if(id < 150){
    String fname = "data"+(id-100)+".csv";
    scopes[id-100].saveData(fname);
    println("Saved as "+fname);
  }
}

// handle serial data
void serialEvent(Serial p) {
  String data = p.readStringUntil(LINE_FEED);
  if (data != null) {
    // println(data);
    vals = int(split(data, ' '));
  }
}


// for test data, you can comment, if not using
int d=0;
ControlTimer ct = new ControlTimer();


int[] getTestValuesSin(){
  int[] vals = new int[scopes.length];

  // this is test data
  if (d==45){
    d=0;
  }

  int sval = (int) abs(sin(d*2)*1023.0f);
  for (int i=0;i<scopes.length;i++){
    vals=sval;
  }

  d++;

  return vals;
}

int oldtime;
int time;
boolean up=false;

int[] getTestValuesSquare(){
  int[] vals = new int[scopes.length];

  ct.setSpeedOfTime(25);
  oldtime=time;
  time = ct.second();

  if (oldtime==time){
    up = !up;
  }

  for (int i=0;i<scopes.length;i++){
    if (up){
      vals=1023;
    }else{
       vals=0;
    }
  }

  return vals;
}

how to connect multiple arduino clients with processing server

$
0
0

i m working on project where multiple arduino clients will be connected to processing server program . server has process the incoming data from each clients and has to display the results. server has to identify connection/ disconnection of each clients, pls help how to proceed .


Combining Strings, converting them to an integer/ array for serial communication

$
0
0

I have some code here that asks for variables one at a time and then prints them at the end. Very basic UI stuff. What I need to do is find a way to turn each string (or character as they are typed) and turn them into a long, float or variable. End goal is to send to an arduino but that comes later. Also, I know this is programmed very inefficiently. It'd be great if I could slim it down. First thing's first though. Make those strings to ints. Thanks in advance! Already tried parseInt, may not be invoking it correctly...

import processing.serial.*;
Serial myPort;

int letter;
int ypos = 25;
int Step = 0;

String input = " ";
String currentString = " ";

String distance;
boolean distanceRec = false;

String timer1;
boolean timer1Rec = false;

String relayTimer;
boolean relayTimerRec = false;

String timer2;
boolean timer2Rec = false;

String speed;
boolean speedRec = false;

String confirm;
boolean confirmVal = false;


void setup() {
  size(640, 900);
  // Create the font
  textFont(createFont("SourceCodePro-Regular.ttf", 36));
//printArray(Serial.list());
//myPort = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
  background(0);
  textSize(14);
  text("Click on the program to begin, enter distance", 25, 25);
  text(input, 25, ypos, 540, 800);

  if(distanceRec == true) {
    text("Distance= ", 25, 400);
    text(distance, 100 ,400);
    text("Enter Timer 1" ,25, 50);
  }

  if(timer1Rec == true) {
    text("Timer 1= ", 25, 425);
    text(timer1, 100 ,425);
    text("Enter Relay Time", 25, 75);
  }

   if(relayTimerRec == true) {
    text("Relay Timer= ", 25, 450);
    text(relayTimer, 125 ,450);
    text("Enter Timer 2", 25, 100);
  }

   if(timer2Rec == true) {
    text("Timer 2= ", 25, 475);
    text(timer2, 100 ,475);
    text("Enter Speed", 25, 125);
  }

  if(speedRec == true) {
    text("Speed= ", 25, 500);
    text(speed, 100 ,500);
    text("CONFIRM THESE VALUES? Y/N", 25, 150);
  }

  if(confirmVal == true) {
    text("Executing...", 25, 525);
    text(distance, 0, 550);
    text(timer1, 100, 550);
    text(relayTimer, 200, 550);
    text(timer2, 300, 550);
    text(speed, 400, 550);


   // myPort.write(distance);
   // println(distance);
   noLoop();
  }
}

void keyTyped() {
    letter = key;
    input = input + key;

      if(letter == ENTER && Step == 0) {
      distance = input;
      distanceRec = true;
      Step++;
      letter = 0;
      input = " ";
    }

     if(letter == ENTER && Step == 1) {
      timer1 = input;
      timer1Rec = true;
      Step++;
      letter = 0;
      input = " ";
    }

     if(letter == ENTER && Step == 2) {
      relayTimer = input;
      relayTimerRec = true;
      Step++;
      letter = 0;
      input = " ";
   }

     if(letter == ENTER && Step == 3) {
      timer2 = input;
      timer2Rec = true;
      Step++;
      letter = 0;
      input = " ";
   }

     if(letter == ENTER && Step == 4) {
      speed = input;
      speedRec = true;
      Step++;
      letter = 0;
      input = " ";
   }

     if(letter == 121 || letter == 89 && Step == 5) {
      confirm = input;
      confirmVal = true;
      Step++;
      letter = 0;
      input = " ";
   }

    if(letter == 78 || letter == 110 && Step == 5) {
    exit();
    // redraw();
   }
}

Using Conductive Paint to Triggers Videos

$
0
0

I am very new to processing and currently doing a project using conductive paint and an arduino and i have the conductive paint working in Arduino using the capacitive sensor, so when its not being touched i see "0's" in the serial port but then when it is touched i get a reading of "59's" and "60's".

1.what i want to do is try get the capacitive sensor working in processing with the conductive paint 2.when the paint is touched i want is to trigger playing a video on a computer. I am new to arduino and processing so i am just wondering how to go about doing this ? thanks :)

Below is my code in arduino using the Capacitive Sensor sketch I have tried using this in processing with the import processing.serial.*; but i really am not sure how to do it. any help on how to do this in a basic level would be greatly appreciated:

include <CapacitiveSensor.h>

CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5);

void setup()

{ Serial.begin(9600); }

void loop()

{ long total1 = cs_2_4.capacitiveSensor(30);
long total2 = cs_2_5.capacitiveSensor(30);
Serial.print("X");
Serial.print(",");
Serial.print(total1);
Serial.print(",");
Serial.println();
Serial.print("Y");
Serial.print(",");
Serial.print(total2);
Serial.print(",");
Serial.println();

delay(100);
}

how to use" Game control plus" lib to control servo ?

$
0
0

how to use" Game control plus" lib (Processing) to control servo with Arduino like that: image

Using Arduino buttons to do something in processing. Best method?

$
0
0

I'm working on a project that is quite simple, but very confusing for a beginner like myself...

In summary, this is the goal: - I push a button (BTN01) on Arduino, my computer plays Sound01A - I flick a swicth (BTN02) on Arduino, it plays Sound02A or Sound02B (depending on it's state) - There will be many, many buttons...

I have a few questions:

1) Is the best method of wiring each button (with two pins) GND and corresponding Digital Input Pin? Do I need a pullup resistor? (I'm testing on Uno but finalising on Mega) ** 2)** Should use "serial.print" or "serial write" in the Arduino code?

3) How should I best label each button state in Arduino that is sent via serial? I was thinking 01a, 01b, 02a, 02b, etc (number is the button/pin, letter is the state eg pushed or not)

4) Should I use some kind of array to m ake the code easier to create and work with? Or should I just have lots of separate if statements (one for each button)?

5) What would be the recommended/ simplest method of receiving the serial inputs in processing?

Using Processing to display a graph of voltage change over time.

$
0
0

Hello there so I am brand spanking new to processing and my Arduino Uno. The project I am doing is a salinity detector (of sorts). However, for the short term, instead of detecting salinity, I am detecting changes in light with a photo-resistor in the form of voltage differences. I am then attempting to graph the change in voltage over time. My code is coming from a tutorial for processing (have never used until now) and now I want to add some additional complexity to the graphed response, here is my code so far:

Arduino Uno:

int val = 0; // variable to store value read at analog pin 3

void setup(){
  Serial.begin(9600); // set up to print to monitor, baud rate = 9600
}

void loop(){
  val = analogRead(3); // read analog input pin 3
  Serial.println(val); // print value to serial monitor
  delay(2);

}

and Processor:

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int xPos = 1;
float inByte = 0;     // Data received from the serial port

void setup()
{
// set window size:
  size(400, 300);
// set up port
String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);

// don't generate a serialEvent() unles you get a newline character:
myPort.bufferUntil('\n');

// set inital background
background(0);
}

void draw(){

  // draw the line:
  stroke(127, 34, 255);
  line(xPos, height, xPos, height - inByte);

  // at the edge of the screen, go back to the beginning:
  if(xPos >= width){
    xPos = 0;
    background(0);
  }else{
    // increment the horizontal postion:
    xPos++;
  }
}

void serialEvent (Serial myPort){

  // get ASCII string:
  String inString = myPort.readStringUntil('\n');

  if(inString !=null){

    // trim off any whitespace:
    inString = trim(inString);

    // convert to an int and map the the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }

}

I know that the value's being displayed in the output window are 1024'th's of the actual voltage so a value of 512 = 2.5v. What I would like though is for that value to be displayed on the x axis of the graph in the form of a scale. I want to add x and y axis labels to my graph.

For instance, the y label could be 0-1000 and the x label would be in seconds. I think the y axis shouldn't be to hard to include because its constant not sure how to edit this output graph though.. is it some kind of GUI? Also, would it even be possible to add an x axis label that scales itself as time goes on?

Maybe I should just forget about x axis labeling or maybe I will need to keep track of the information and send it to a file to be graphed later??

Not entirely sure how I should go about the project from here, any advice? I do know that eventually I am going to need at least a y axis label because I want to detect changes in salinity over time from saline rich water to less saline rich water (I will poor in fresh water). My salinity detector will just be two nails spaced about 1 cm apart and will be connected to the circuit in the same configuration as my photo-resistor circuit. For now, if I could just get a y label and a title to the graph that would be good.

Viewing all 747 articles
Browse latest View live