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

Embedded Software & Processing

$
0
0

I just found this very interesting sight by way of a GitHub Arduino sketch! Before I dive into "Processing" my question is . . . Can these Awesome graphics and math routines somehow be used to display on (example) a 3" TFT run by a microcontroller?

Thanks

Ken


Problem with Pulse Sensor Visualizer

$
0
0

Hello! I am working with pulse sensor. The LED from pin no 13 is blinking according to the pulse. Its working.

But pulse sensor amped visualizer is nor working! It just shows a straight line and does not give BPM. I used code from this site for both arduino and processing code.

https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino I am using Windows 7(32 bit), arduino IED 1.6.9 And processing 3.1.1 software. I gave same baud rate to both arduino and processing code. Please suggest me how can I solve. If possible please give the screenshot , how to fix it Thanks pulse

Processing Code to Display Amped Visualizer

$
0
0

Hello guys, I need a helping hand here. I am new to this processing software and i obtained a processing code along with my brand new Pulse Sensor. I successfully call out the visualizer ( printed screen below ), but there was no reading on the graph, it just drop to zero although my pulse sensor is working perfectly with Arduino Uno. Please help me....thanks anyway

Visualizer

Here is my code:

/**
THIS PROGRAM WORKS WITH PulseSensorAmped_Arduino-xx ARDUINO CODE
THE PULSE DATA WINDOW IS SCALEABLE WITH SCROLLBAR AT BOTTOM OF SCREEN
PRESS 'S' OR 's' KEY TO SAVE A PICTURE OF THE SCREEN IN SKETCH FOLDER (.jpg)
MADE BY JOEL MURPHY AUGUST, 2012
*/


import processing.serial.*;
PFont font;
Scrollbar scaleBar;

Serial port;

int Sensor;      // HOLDS PULSE SENSOR DATA FROM ARDUINO
int IBI;         // HOLDS TIME BETWEN HEARTBEATS FROM ARDUINO
int BPM;         // HOLDS HEART RATE VALUE FROM ARDUINO
int[] RawY;      // HOLDS HEARTBEAT WAVEFORM DATA BEFORE SCALING
int[] ScaledY;   // USED TO POSITION SCALED HEARTBEAT WAVEFORM
int[] rate;      // USED TO POSITION BPM DATA WAVEFORM
float zoom;      // USED WHEN SCALING PULSE WAVEFORM TO PULSE WINDOW
float offset;    // USED WHEN SCALING PULSE WAVEFORM TO PULSE WINDOW
color eggshell = color(255, 253, 248);
int heart = 0;   // This variable times the heart image 'pulse' on screen
//  THESE VARIABLES DETERMINE THE SIZE OF THE DATA WINDOWS
int PulseWindowWidth = 490;
int PulseWindowHeight = 512;
int BPMWindowWidth = 180;
int BPMWindowHeight = 340;
boolean beat = false;    // set when a heart beat is detected, then cleared when the BPM graph is advanced


void setup() {
  size(700, 600);  // Stage size
  frameRate(100);
  font = loadFont("Arial-BoldMT-24.vlw");
  textFont(font);
  textAlign(CENTER);
  rectMode(CENTER);
  ellipseMode(CENTER);
// Scrollbar constructor inputs: x,y,width,height,minVal,maxVal
  scaleBar = new Scrollbar (400, 575, 180, 12, 0.5, 1.0);  // set parameters for the scale bar
  RawY = new int[PulseWindowWidth];          // initialize raw pulse waveform array
  ScaledY = new int[PulseWindowWidth];       // initialize scaled pulse waveform array
  rate = new int [BPMWindowWidth];           // initialize BPM waveform array
  zoom = 0.75;                               // initialize scale of heartbeat window

// set the visualizer lines to 0
 for (int i=0; i<rate.length; i++){
    rate[i] = 555;      // Place BPM graph line at bottom of BPM Window
   }
 for (int i=0; i<RawY.length; i++){
    RawY[i] = height/2; // initialize the pulse window data line to V/2
 }

// GO FIND THE ARDUINO
  println(Serial.list());    // print a list of available serial ports
  // choose the number between the [] that is connected to the Arduino
  port = new Serial(this, Serial.list()[0], 115200);  // make sure Arduino is talking serial at this baud rate
  port.clear();            // flush buffer
  port.bufferUntil('\n');  // set buffer full flag on receipt of carriage return
}

void draw() {
  background(0);
  noStroke();
// DRAW OUT THE PULSE WINDOW AND BPM WINDOW RECTANGLES
  fill(eggshell);  // color for the window background
  rect(255,height/2,PulseWindowWidth,PulseWindowHeight);
  rect(600,385,BPMWindowWidth,BPMWindowHeight);

// DRAW THE PULSE WAVEFORM
  // prepare pulse data points
  RawY[RawY.length-1] = (1023 - Sensor) - 212;   // place the new raw datapoint at the end of the array
  zoom = scaleBar.getPos();                      // get current waveform scale value
  offset = map(zoom,0.5,1,150,0);                // calculate the offset needed at this scale
  for (int i = 0; i < RawY.length-1; i++) {      // move the pulse waveform by
    RawY[i] = RawY[i+1];                         // shifting all raw datapoints one pixel left
    float dummy = RawY[i] * zoom + offset;       // adjust the raw data to the selected scale
    ScaledY[i] = constrain(int(dummy),44,556);   // transfer the raw data array to the scaled array
  }
  stroke(250,0,0);                               // red is a good color for the pulse waveform
  noFill();
  beginShape();                                  // using beginShape() renders fast
  for (int x = 1; x < ScaledY.length-1; x++) {
    vertex(x+10, ScaledY[x]);                    //draw a line connecting the data points
  }
  endShape();

// DRAW THE BPM WAVE FORM
// first, shift the BPM waveform over to fit then next data point only when a beat is found
 if (beat == true){   // move the heart rate line over one pixel every time the heart beats
   beat = false;      // clear beat flag (beat flag waset in serialEvent tab)
   for (int i=0; i<rate.length-1; i++){
     rate[i] = rate[i+1];                  // shift the bpm Y coordinates over one pixel to the left
   }
// then limit and scale the BPM value
   BPM = min(BPM,200);                     // limit the highest BPM value to 200
   float dummy = map(BPM,0,200,555,215);   // map it to the heart rate window Y
   rate[rate.length-1] = int(dummy);       // set the rightmost pixel to the new data point value
 }
 // GRAPH THE HEART RATE WAVEFORM
 stroke(250,0,0);                          // color of heart rate graph
 strokeWeight(2);                          // thicker line is easier to read
 noFill();
 beginShape();
 for (int i=0; i < rate.length-1; i++){    // variable 'i' will take the place of pixel x position
   vertex(i+510, rate[i]);                 // display history of heart rate datapoints
 }
 endShape();

// DRAW THE HEART AND MAYBE MAKE IT BEAT
  fill(250,0,0);
  stroke(250,0,0);
  // the 'heart' variable is set in serialEvent when arduino sees a beat happen
  heart--;                    // heart is used to time how long the heart graphic swells when your heart beats
  heart = max(heart,0);       // don't let the heart variable go into negative numbers
  if (heart > 0){             // if a beat happened recently,
    strokeWeight(8);          // make the heart big
  }
  smooth();   // draw the heart with two bezier curves
  bezier(width-100,50, width-20,-20, width,140, width-100,150);
  bezier(width-100,50, width-190,-20, width-200,140, width-100,150);
  strokeWeight(1);          // reset the strokeWeight for next time


// PRINT THE DATA AND VARIABLE VALUES
  fill(eggshell);                                       // get ready to print text
  text("Pulse Sensor Amped Visualizer 1.1",245,30);     // tell them what you are
  text("IBI " + IBI + "mS",600,585);                    // print the time between heartbeats in mS
  text(BPM + " BPM",600,200);                           // print the Beats Per Minute
  text("Pulse Window Scale " + nf(zoom,1,2), 150, 585); // show the current scale of Pulse Window

//  DO THE SCROLLBAR THINGS
  scaleBar.update (mouseX, mouseY);
  scaleBar.display();

//
}  //end of draw loop


//.............................................scalebar (name of file)............................................................................................................


/**
    THIS SCROLLBAR OBJECT IS BASED ON THE ONE FROM THE BOOK "Processing" by Reas and Fry
*/

class Scrollbar{
 int x,y;               // the x and y coordinates
 float sw, sh;          // width and height of scrollbar
 float pos;             // position of thumb
 float posMin, posMax;  // max and min values of thumb
 boolean rollover;      // true when the mouse is over
 boolean locked;        // true when it's the active scrollbar
 float minVal, maxVal;  // min and max values for the thumb

 Scrollbar (int xp, int yp, int w, int h, float miv, float mav){ // values passed from the constructor
  x = xp;
  y = yp;
  sw = w;
  sh = h;
  minVal = miv;
  maxVal = mav;
  pos = x - sh/2;
  posMin = x-sw/2;
  posMax = x + sw/2;  // - sh;
 }

 // updates the 'over' boolean and position of thumb
 void update(int mx, int my) {
   if (over(mx, my) == true){
     rollover = true;            // when the mouse is over the scrollbar, rollover is true
   } else {
     rollover = false;
   }
   if (locked == true){
    pos = constrain (mx, posMin, posMax);
   }
 }

 // locks the thumb so the mouse can move off and still update
 void press(int mx, int my){
   if (rollover == true){
    locked = true;            // when rollover is true, pressing the mouse button will lock the scrollbar on
   }else{
    locked = false;
   }
 }

 // resets the scrollbar to neutral
 void release(){
  locked = false;
 }

 // returns true if the cursor is over the scrollbar
 boolean over(int mx, int my){
  if ((mx > x-sw/2) && (mx < x+sw/2) && (my > y-sh/2) && (my < y+sh/2)){
   return true;
  }else{
   return false;
  }
 }

 // draws the scrollbar on the screen
 void display (){

  noStroke();
  fill(255);
  rect(x, y, sw, sh);      // create the scrollbar
  fill (250,0,0);
  if ((rollover == true) || (locked == true)){
   stroke(250,0,0);
   strokeWeight(8);           // make the scale dot bigger if you're on it
  }
  ellipse(pos, y, sh, sh);     // create the scaling dot
  strokeWeight(1);            // reset strokeWeight
 }

 // returns the current value of the thumb
 float getPos() {
  float scalar = sw / sw;  // (sw - sh/2);
  float ratio = (pos-(x-sw/2)) * scalar;
  float p = minVal + (ratio/sw * (maxVal - minVal));
  return p;
 }
 }

//...........................................serialevent (name of file)..........................................................................................................



void serialEvent(Serial port){
   String inData = port.readStringUntil('\n');
   inData = trim(inData);                 // cut off white space (carriage return)

   if (inData.charAt(0) == 'S'){          // leading 'S' for sensor data
     inData = inData.substring(1);        // cut off the leading 'S'
     Sensor = int(inData);                // convert the string to usable int
   }
   if (inData.charAt(0) == 'B'){          // leading 'B' for BPM data
     inData = inData.substring(1);        // cut off the leading 'B'
     BPM = int(inData);                   // convert the string to usable int
     beat = true;                         // set beat flag to advance heart rate graph
     heart = 20;                          // begin heart image 'swell' timer
   }
 if (inData.charAt(0) == 'Q'){            // leading 'Q' means IBI data
     inData = inData.substring(1);        // cut off the leading 'Q'
     IBI = int(inData);                   // convert the string to usable int
   }
}

Read data from serial(from another arduino through xbee) to usable string

$
0
0

this is sender node :

sender

My problem is when it receive "node1" from sender through xbee, the condition is aborted.. BUT, when i manually write in serial, the condition is worked.. i think the data sent by sender is not actually "node1"..even when i Serial.print(), it shows ""node1" physically.

this is receiver node:

receiver

Arduino; Make mp3 volume change when pressing a button

$
0
0

I would have five tracks of mp3, each connected to a button (arduino),playing on an infinite loop at volume 0. the buttons would be connected to analog, so A0,A1,A2,A3,A4. when i press the button, the volume of the mp3 file would go up to 100. The music would be on my desktop and the music would be playing through my laptop speakers.

URGENT in need of help with processing code SRF10 ultrasonic sensor

$
0
0

``Hello, im in need of help with my project using SRF10 ultrasonic sensor. Im and using arduino + processing for our project but our coding is not strong. I have 2 ultrasonic which use to track moving object. I need help in showing the object location and showing it change when the object changes location. I currently able to show a printed value but only for one sensor displayed on processing. Any kind soul able to help :)

Here is our processing code:

import processing.serial.*;
//import cc.arduino.*;
//println(Arduino.list());
 String val;
Serial myPort;

float Distance1 = 0, Distance2 = 0;
float LocationX=0; // Assumed location of an object (X,Y)
float LocationY=0;
float SRF1_x=300;  // location of SRF1 (x,y)
float SRF1_y=100;
float SRF2_x=500;  // location of SRF2 (x,y)
float SRF2_y=100;
float AngularRes=PI/180*10; //   Angle change step size
int xPos = 1;      // horizontal position of the graph

void setup()
{
  size(1000, 700);
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
  background(200);
  smooth();
  myPort.bufferUntil('\n');
  DrawGrid();
}

void draw()
{
      if( myPort.available() > 0)
      {  // If data is available,
        val = myPort.readStringUntil('\n');
      }
  println(val);
     FindLocation();
//     background(300, 300, 300);
     fill(300);
     ellipse(SRF1_x,SRF1_y,25,25); // location of SRF1
     fill(100);
     ellipse(SRF2_x,SRF2_y,25,25); // location of SRF2
     fill(400);
     ellipse(LocationX,LocationY,10,10); // actual location of an object


}

void serialEvent(Serial myPort)
{
  String str = myPort.readStringUntil('\n');
  if (str != null )
  {
      str = trim(str); //remove whitespace around our values
      float  DistanceArr[]=float (split(str, ','));
      Distance1= map( DistanceArr[0], 0, 540, 0, 3000); // map distance of SRF1 to another range
      Distance2= map( DistanceArr[1], 0, 540, 0, 3000); // map distance of SRF2 to another range
  }
}

void FindLocation(){
     float MinimumDist = 50000;
     float x_CL_SRF1, y_CL_SRF1, x_CL_SRF2, y_CL_SRF2,Cal_MinimumDist; // x-y coordinates along two circles
     for (float theta1 = 0; theta1 < PI; theta1 = theta1+AngularRes) {
         x_CL_SRF1=SRF1_x +Distance1*cos(theta1);   // get x-y coordinates along circle for SRF1
         y_CL_SRF1=SRF1_y +Distance1*sin(theta1);
         ellipse(x_CL_SRF1,y_CL_SRF1,10,10);
         for (float theta2 = 0; theta2 < PI; theta2 = theta2+AngularRes) {
              x_CL_SRF2=SRF2_x +Distance2*cos(theta2);  // get x-y coordinates along circle for SRF2
              y_CL_SRF2=SRF2_y +Distance2*sin(theta2);
              ellipse(x_CL_SRF2,y_CL_SRF2,10,10);
              Cal_MinimumDist=sqrt(sq(x_CL_SRF1- x_CL_SRF2)+sq(y_CL_SRF1- y_CL_SRF2));
              if (Cal_MinimumDist<MinimumDist){
                  MinimumDist=Cal_MinimumDist;
                  LocationX=x_CL_SRF1;
                  LocationY=y_CL_SRF1;
               }

         }
    }
}

void DrawGrid() {
    for (int i = 0; i < 700; i = i+100) {
        line(0, i, 990, i);
        }

        for (int i = 0; i < 1000; i = i+100) {
             line(i, 0, i, 690 );
        }
}

Here is the arduino code: /* * * rosserial srf02 Ultrasonic Ranger Example * * This example is calibrated for the srf02 Ultrasonic Ranger. * * By Poh Hou Shun 24 September 2015 */

//#include <Sonar_srf02.h> //srf02 specific library
#include <Wire.h>
//#include <ros.h>
//#include <std_msgs/Float32.h>


//Set up the ros node and publisher
//std_msgs::Float32 sonar_msg;
//ros::Publisher pub_sonar("sonar", &sonar_msg);
//ros::NodeHandle nh;

//Sonar_srf02 MySonar; //create MySonar object

#define COMMANDREGISTER 0x00
#define RESULTREGISTER  0x02

#define CENTIMETERS 0x51
// use 0x50 for inches
// use 0x51 for centimeters
// use 0x52 for ping microseconds

#define NO_OF_SENSORS 2

int SEQUENCE[] = {115, 116};

int reading = 0;
String stringData;

void setup()
{

  Wire.begin();                // join i2c bus (address optional for master)
  Serial.begin(9600);          // start serial communication at 9600bps

  //nh.initNode();
  //nh.advertise(pub_sonar);

}


long publisher_timer;

void loop()
{

  if (millis() > publisher_timer || 1) {

    for (int i = 0; i < NO_OF_SENSORS; i++) {
      takeData(SEQUENCE[i]);
    }

    // step 2: wait for readings to happen
    delay(70);                   // datasheet suggests at least 65 milliseconds

    readData(SEQUENCE[0]);

    stringData = String(reading);
    Serial.print(reading);

    for (int i = 1; i < NO_OF_SENSORS; i++) {
      readData(SEQUENCE[i]);
      stringData = ' ' + String(reading);
      Serial.print(' ');
      Serial.print(reading);
    }

    //stringData = stringData + '\0';

    //sonar_msg.data = stringData;
    //pub_sonar.publish(&sonar_msg);

    publisher_timer = millis() + 4000; //publish once a second
    //Serial.println(sensorReading);
    Serial.println('\0');

  }

  //Serial.println(stringData);   // print the reading
  //nh.spinOnce();

}

void takeData(int address) {

  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(address); // transmit to device #112 (0x70)

  // the address specified in the datasheet is 224 (0xE0)
  // but i2c adressing uses the high 7 bits so it's 112
  Wire.write(byte(COMMANDREGISTER));      // sets register pointer to the command register (0x00)
  Wire.write(byte(CENTIMETERS));      // command sensor to measure in "centimeters" (0x51)

  Wire.endTransmission();      // stop transmitting

}

void readData(int address) {

  // step 3: instruct sensor to return a particular echo reading
  Wire.beginTransmission(address); // transmit to device #112
  Wire.write(byte(RESULTREGISTER));      // sets register pointer to echo #1 register (0x02)
  Wire.endTransmission();      // stop transmitting

  // step 4: request reading from sensor
  Wire.requestFrom(address, 2);    // request 2 bytes from slave device #112

  // step 5: receive reading from sensor
  if (2 <= Wire.available()) { // if two bytes were received
    reading = Wire.read();  // receive high byte (overwrites previous reading)
    reading = reading << 8;    // shift high byte to be high 8 bits
    reading |= Wire.read(); // receive low byte as lower 8 bits
  }

  delay(250);
  //Serial.println(reading);

}

How to show serial data and interactive buttons using G4P Library

$
0
0

Hello! I want create a window that shows serial data from an arduino, in this window I want to put 2 buttons, the first to start showing serial data, and the second to save the data on a .txt file. I don't know very well how to use G4P library, i'm able to show the data but I don't know how to put buttons in the same window of the data. Someone can help me?

Working on binary data

$
0
0

I am facing some problems sending and using a byte from arduino to processing. My goal would be to make an array of boolean from this byte. If you can, tell me if i am doing something wrong:

In arduino i send a single byte using Serial.write(); In processing I receive using Serial.read();

Problems:

1) looks like that i have a problem of comunication because i reveice much more bytes than i wait. Baudrate is the same and the port is correct.

2) There must be something that i miss because i am forced to use an int to store the value of Serial.read(), why can't i use a byte?

3) i have also problems in working on this byte using the normal | & and ^ operations, same problem as point 2, why am i fprced to use an int to use them? Them are bitwise operations and i would like to use bytes not int!

4) how can i use directly binary data? For example in arduino i use 'B101010' but here seems that i can use only hex


WIFI list & Connection by android mode (at Processing Tool)

$
0
0
import android.net.wifi.*;
import android.content.*;
import java.util.*;

Context context;

void connect_to_wifi(){

  //create wifi connection
        String networkSSID = "";
        String networkPass = "";

        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + networkSSID + "\"";   // Please note the quotes. String should contain ssid in quotes

         //For WPA network you need to add passphrase like this:

            conf.preSharedKey = "\""+ networkPass +"\"";

        //Then, you need to add it to Android wifi manager settings:
        WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
        wifiManager.addNetwork(conf);

        //And finally, you might need to enable it, so Android conntects to it:
        List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
        for( WifiConfiguration i : list ) {
            if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
                 wifiManager.disconnect();
                 wifiManager.enableNetwork(i.networkId, true);
                 wifiManager.reconnect();

                 break;
            }
         }
}

void setup() {
  size(480,800);
  noStroke();
  fill(255);
  rectMode(CENTER);     // This sets all rectangles to draw from the center point
  connect_to_wifi();
}

void draw() {
  background(#FF9900);
  rect(width/2, height/2, 150, 150);
}

Error Message : FATAL EXCEPTION: Animation Thread Please solve the problem. Help.

inByte == "A" play video

$
0
0

Hi, I have a sketch which listens to arduino and when it reads incoming bytes then plays sounds. I am having hard time changing that to play video instead. Could you please advice me.

import processing.serial.*;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
int loopcount;

int bgcolor;                 // Background color
int fgcolor;                 // Fill color
Serial myPort;                       // The serial port
int[] serialInArray = new int[3];    // Where we'll put what we receive
int serialCount = 0;                 // A count of how many bytes we receive
int xpos, ypos;                  // Starting position of the ball
boolean firstContact = false;        // Whether we've heard from the microcontroller

void setup() {
  size(256, 256);  // Stage size
  noStroke();      // No border on the next thing drawn
  minim = new Minim(this);



  printArray(Serial.list());


  String portName = Serial.list()[0];
  //myPort = new Serial(this, "/dev/cu.usbmodem1510721", 9600);
  myPort = new Serial(this, "/dev/cu.HC-05-DevB", 9600);
}

void draw() {
  background(bgcolor);
  fill(fgcolor);
  // Draw the shape
}

void serialEvent(Serial myPort) {

  int inByte = myPort.read();

  if (firstContact == false) {
    if (inByte == 'A') {
      player = minim.loadFile("drumgroove_3.wav");
       player.loop();
      // ask for more
    }

    if (inByte == 'F'){
      player = minim.loadFile("sound_7.mp3");
 player.play();
  }

     if(inByte == 'B'){
player = minim.loadFile("sound_2.mp3");
player.play();
}
    if (inByte == 'C'){
      player = minim.loadFile("sound_6_converted.wav");
      player.loop(2);
      loopcount = 3;
    }

    if (inByte == 'D'){
      player = minim.loadFile("sound_4.mp3");
      player.play();
    }

    if (inByte == 'E'){
      player = minim.loadFile("sound_5.mp3");
      player.play();
    }


}
}

Spin Arrow when inByte == "X" read.

$
0
0

Hi, Im pretty new to processing, I have a sketch which I figured out before. It reads for incoming bytes coming from arduino.

I've used it before to trigger sounds. Which was fine triggering them within method where the bytes are read.

I am trying to make it now spin an arrow.

I have setup a function for 'spinning an arrow' which I then can use in 'draw', however, I don't know how to make a statement saying inByte read in 'void serialEvent(Serial myPort)' should trigger 'spin();' in 'void draw()'. Hope it makes sense and please please help me.

processing connecting to a webcam or a beamer

$
0
0

Hi, I am pretty new to processing and just started to a group project to make a light sensing thing for children who are scared to the dark, which could turn on a attractive fun video on a wall or a celling throughout their room after sensing the dark.

I would bring arduino code to processing to sense the light value but then, I have no idea how to project the video after sensing the light value? any ideas?

thank you!

difficulty connecting arduino to processing & difficulty in servo control T_T

$
0
0

Hi there,

Recently I want to make a project using processing to capture mind wave and send 0, 1, 2 to Arduino to control a servo. I encountered 3 problems:

1, Processing's serial cannot transmit to Arduino, but it can send 0 at 1st time, and then nothing works.

2, My servo does not stick to the angle I wrote to him. It keeps spinning around and around..

3, I intend to make servo turn clock wise when receiving '1', and anticlockwise receiving '2', but it dose not do anticlockwise all the time, it turns anticlockwise for 3seconds, and then turn clockwise, and repeat.....

Following are my codes. Each of the problems being solved can save me a step from the fire of July.......

Processing:

//Thinkgear
import neurosky.*;
import org.json.*;

//Arduino
import cc.arduino.*;
import org.firmata.*;
import processing.serial.*;

ThinkGearSocket neuroSocket;
int attention=10;
int meditation=10;
int attentionBrightness = 0;

int attentionValue = 40;
int meditationValue = 40;

Arduino arduino;
Serial myPort;  // Create object from Serial class
int ledPin = 3;
int servoPin = 9;



void setup()
{
  size(600,600);

  //ThinkGear Connection
  ThinkGearSocket neuroSocket = new ThinkGearSocket(this);
  try {neuroSocket.start();}
  catch (Exception e) {println("Is Thinkgear running?");}
  smooth();
  frameRate(10);

  //Arduino Connection
  String portName = Serial.list()[5]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
  printArray(Serial.list());
}


void draw() {

  visualisation();

  //case 0: halt & LED BLINK
  if (attention<attentionValue)
    {
      if(meditation<=meditationValue)
      { myPort.write('0');  println("0"); }

   //case 1:  close & LED OFF
      else if (meditation>meditationValue)
     { myPort.write('1');   println("1"); }
    }

  //case 2:  open & LED ON
  else if (attention>attentionValue)
  { myPort.write('2');  println("2"); }
}


////alternative test
//   if (mousePressed == true)
//   { myPort.write('0');  println("0"); }

//   //case 1:  close & LED OFF
//   if (mousePressed==false && keyPressed==false)
//   { myPort.write('1');   println("1"); }

//  //case 2:  open & LED ON
//  if (keyPressed==true)
//  { myPort.write('2');  println("2");}
//}


void poorSignalEvent(int sig) {
  println("SignalEvent "+sig);
}

public void attentionEvent(int attentionLevel)
{
  println("Attention Level: " + attentionLevel);
  attention = attentionLevel;
}


void meditationEvent(int meditationLevel)
{
  println("Meditation Level: " + meditationLevel);
  meditation = meditationLevel;
}

void stop() {
  neuroSocket.stop();
  super.stop();
}

and Arduino,

#include <VarSpeedServo.h>

//initiate
VarSpeedServo myservo;
int pos = 0;
int servoPin = 9;
int ledPin = 3;


//conncect to processing
char val;


void setup()
{
  //led
  pinMode(ledPin,OUTPUT);

  //servo
  myservo.attach(servoPin);
  myservo.write(0,255,true);  //reset position
  delay(1000);
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())
  val = Serial.read();
  if(val =='1')
  {
  digitalWrite(ledPin,LOW);
  myservo.attach(servoPin);
  int pos=0;
  while(pos < 90)        // from 0 to 180
  {
    myservo.write(pos,10,true);
    Serial.println(myservo.read());
    delay(5);
    pos += 1;
  }

//  digitalWrite(servoPin,LOW);
  delay(20);
  }

  if (val =='2')
  {
  digitalWrite(ledPin,HIGH);
  myservo.attach(servoPin);
  int pos = 90;
  while(pos>=1)   //from 180 to 0
  {
    myservo.write(pos,10,true);
    Serial.println(myservo.read());
    pos-=1;
   digitalWrite(servoPin, HIGH);
   delay(20);
  }
  }

  else if (val == '0')
  {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
  myservo.detach();
  }
  }

4x4 Matrix Keypad in Processing ???

$
0
0

Hey, does anyone know if there's a way to use a 4x4 Matrix Keypad in processing???? Help would be much appreciated

바카라사이트추천〃〃BBF900。CoM〃〃보스카지노

$
0
0

보스카지노\\〃〃BBF900。CoM〃〃\\카지노사이트추천ツ생중계카지노わ온라인바카라わ카지노사이트わ인터넷카지노わ보스카지노わ바카라사이트わ카지노사이트わ인터넷카지노わ온라인바카라わ온라인카지노わ보스카지노わ바카라사이트わ온라인바카라わ인터넷카지노わ온라인카지노わ카지노사이트わ보스카지노わ바카라사이트わ인터넷카지노わ온라인바카라わ카지노사이트わ온라인카지노わ보스카지노わ바카라사이트わ온라인카지노わ온라인바카라わ카지노사이트わ인터넷카지노わ보스카지노わ바카라사이트わ카지노사이트わ인터넷카지노わ온라인바카라わ온라인카지노わ보스카지노わ바카라사이트わ온라인바카라わ인터넷카지노わ온라인카지노わ카지노사이트わ보스카지노わ바카라사이트わ인터넷카지노わ온라인바카라わ카지노사이트わ온라인카지노わ보스카지노わ바카라사이트わ온라인카지노わ온라인바카라わ카지노사이트わ인터넷카지노わ보스카지노わ바카라사이트わ카지노사이트わ인터넷카지노わ온라인바카라わ온라인카지노わ보스카지노わ바카라사이트わ온라인바카라わ인터넷카지노わ온라인카지노わ카지노사이트わ보스카지노わ바카라사이트わ인터넷카지노わ온라인바카라わ카지노사이트わ온라인카지노わ보스카지노わ바카라사이트わ온라인카지노わ온라인바카라わ카지노사이트わ인터넷카지노わ보스카지노わ바카라사이트わ카지노사이트わ인터넷카지노わ온라인바카라わ온라인카지노わ보스카지노わ바카라사이트わ온라인바카라わ인터넷카지노わ온라인카지노わ카지노사이트わ보스카지노わ바카라사이트わ인터넷카지노わ온라인바카라わ카지노사이트わ온라인카지노わ보스카지노わ바카라사이트わ온라인카지노わ온라인바카라わ카지노사이트わ인터넷카지노わ보스카지노わ바카라사이트わ카지노사이트わ인터넷카지노わ온라인바카라わ온라인카지노わ보스카지노わ바카라사이트わ온라인바카라わ인터넷카지노わ온라인카지노わ카지노사이트わ보스카지노わ바카라사이트わ인터넷카지노わ온라인바카라わ카지노사이트わ온라인카지노わ보스카지노わ바카라사이트わ온라인카지노わ온라인바카라わ카지노사이트わ인터넷카지노わ보스카지노わ바카라사이트わ카지노사이트わ인터넷카지노わ온라인바카라わ온라인카지노わ보스카지노わ바카라사이트わ온라인바카라わ인터넷카지노わ온라인카지노わ카지노사이트わ보스카지노わ바카라사이트わ인터넷카지노わ온라인바카라わ카지노사이트わ온라인카지노わ보스카지노わ바카라사이트わ카지노사이트わ온라인바카라わ온라인카지노わ실전바카라


connecting an lcd to processing

$
0
0

Hello I used a processing sketch that shows a graphic form of information recieved from a pulse sensor. I would like to take that information and display it on an lcd screen. I don't know how to take that data and send it out of processing and into the lcd, so I could really use some help! thanks

Port.write question

$
0
0

I am trying to send the following: H254,254\n. I am not sure I am formatting it correctly in the write statement. Any help would be so appreciated!!!!

value1=254; value2=254; myPort.write("H" + value1 + value2 + "\n");

Processing to firebase

$
0
0

Hi, I am newbie in processing and all network things. Is that possible for processing get data from arduino and upload it to the firebase? Any tutorials for this section?

Map real time accelerometer values to 3D objects

$
0
0

Hi, I am trying to implement a situation where a 3D object in the IDE orients itself according to the values it gets from an accelerometer outside the IDE. The values are read using serial port. How do I use the rotate function to achieve this?

Thanks in advance!

Windows GUI in a Mac, how do I do that?

$
0
0

I have a GUI that was built with Processing on a Windows 10 machine. I need to be able to use it with a Mac.

How do I export it so I can use it on a Mac.

Viewing all 747 articles
Browse latest View live