<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with #adafruit - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=%23adafruit</link>
      <pubDate>Sun, 08 Aug 2021 20:41:09 +0000</pubDate>
         <description>Tagged with #adafruit - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/tagged%23adafruit/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>My MCP3008 did not send any value to processing!?</title>
      <link>https://forum.processing.org/two/discussion/26496/my-mcp3008-did-not-send-any-value-to-processing</link>
      <pubDate>Fri, 23 Feb 2018 07:19:18 +0000</pubDate>
      <dc:creator>TuangPing</dc:creator>
      <guid isPermaLink="false">26496@/two/discussions</guid>
      <description><![CDATA[<p>There are a few question that has been asked in this forum here that I've followed them already but both did not work with my Rpi.</p>

<p>Here are two from a few of them I have worked around but fail.
<a rel="nofollow" href="https://forum.processing.org/two/discussion/14033/raspberrypi2-spi-mcp3008">(1)</a>, <a rel="nofollow" href="https://github.com/processing/processing/tree/master/java/libraries/io/examples/SPIAnalogDigitalOOP8">(2)</a>
I see the 2nd example from a site that seems like a legit Github of Processing team (?) is a very updated one but I still get only 0 from it. However, when run the python in terminal my sensors do work well.</p>

<p>I'm using Rpi 3 B and my code is exactly copy and paste from the 2nd. I've created a new folder in Rpi and have two file.pde one is a class and one is a main function (setup and draw).</p>

<p>So, what else should I do or any info that I should looking into to fix this problem?</p>
]]></description>
   </item>
   <item>
      <title>p5.js and ws2811/ws2812 NeoPixel RGB LEDs</title>
      <link>https://forum.processing.org/two/discussion/24367/p5-js-and-ws2811-ws2812-neopixel-rgb-leds</link>
      <pubDate>Wed, 04 Oct 2017 02:01:18 +0000</pubDate>
      <dc:creator>gdsports</dc:creator>
      <guid isPermaLink="false">24367@/two/discussions</guid>
      <description><![CDATA[<p>I experimented with an ESP8266 driving WS281x RGB LEDs (also known as Adafruit NeoPixels) using a p5.js sketch to create the pixel images. The ESP8266 web server and web socket server libraries make this easy to do. node.js and socket.io are not used for these demos. The source code is available on <a rel="nofollow" href="https://github.com/gdsports/p5-js-ws281x">github</a>. A few more details are <a rel="nofollow" href="https://esp8266-notes.blogspot.com/2017/10/p5js-and-ws281x-rgb-leds.html">here</a></p>

<p><img src="https://github.com/gdsports/p5-js-ws281x/raw/master/images/p5jsws281x.gif" alt="Dot follow finger" /></p>
]]></description>
   </item>
   <item>
      <title>Reading data from a bluetooth port</title>
      <link>https://forum.processing.org/two/discussion/22396/reading-data-from-a-bluetooth-port</link>
      <pubDate>Thu, 04 May 2017 21:12:02 +0000</pubDate>
      <dc:creator>Mat007</dc:creator>
      <guid isPermaLink="false">22396@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I am trying to read data sent by a nRF51822 Bluetooth LE module (Adafruit Feather M0 Bluefruit LE). I modified the bleuart_datamode sketch given as example to send the same data via bluetooth and USB serial.
I can see the Bluetooth data on my iPad with the Bluefruit LE connect app so I know that my board is sending stuff in the air. Using processing however I can read the serial data but I get a null string from bluetooth.
I suspected a baud rate problem so I tried everything... I don't get any error message though. The code is compiling and running but I get a null string...</p>

<p>Any idea ? Thanks !</p>

<pre><code>import processing.serial.*; 

Serial mySerialPort;          
Serial myBluePort;
PFont myFont;          
String serialString;       
String blueString;
int lf = 10;            // ASCII linefeed aka '/n'

void setup() { 

  frameRate(1000);
  size(400,200); 
  myFont = loadFont("ArialMT-18.vlw");  // Processing&gt;Tools&gt;Create Font 
  textFont(myFont, 18); 
  printArray(Serial.list());  

  mySerialPort = new Serial(this, Serial.list()[1], 115200); 
  mySerialPort.bufferUntil(lf); 

  myBluePort = new Serial(this, Serial.list()[0], 1200); 
  //myBluePort = new Serial(this, Serial.list()[0], 2400); 
  //myBluePort = new Serial(this, Serial.list()[0], 4800); 
  //myBluePort = new Serial(this, Serial.list()[0], 9600); 
  //myBluePort = new Serial(this, Serial.list()[0], 14400);
  //myBluePort = new Serial(this, Serial.list()[0], 19200); 
  //myBluePort = new Serial(this, Serial.list()[0], 28800); 
  //myBluePort = new Serial(this, Serial.list()[0], 38400); 
  //myBluePort = new Serial(this, Serial.list()[0], 57600); 
  //myBluePort = new Serial(this, Serial.list()[0], 76800); 
  //myBluePort = new Serial(this, Serial.list()[0], 115200); 
  //myBluePort = new Serial(this, Serial.list()[0], 230400); 
  //myBluePort = new Serial(this, Serial.list()[0], 250000); 
  //myBluePort = new Serial(this, Serial.list()[0], 460800); 
  //myBluePort = new Serial(this, Serial.list()[0], 921600); 
  //myBluePort = new Serial(this, Serial.list()[0], 1000000); 
   myBluePort.bufferUntil(lf);
} 

void draw() { 

  if ( mySerialPort.available() &gt; 0) serialString = mySerialPort.readString();
  if ( myBluePort.available() &gt; 0) blueString = myBluePort.readString();

  background(0); 
  text("Receiving serial data : " + trim(serialString), 10,20); 
  text("Receiving bluetooth data : " + trim(blueString), 10,40); 

} 
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to execute python commands in a Processing script? RE: Controlling Adafruit Servo Hat</title>
      <link>https://forum.processing.org/two/discussion/21478/how-to-execute-python-commands-in-a-processing-script-re-controlling-adafruit-servo-hat</link>
      <pubDate>Sun, 19 Mar 2017 15:23:21 +0000</pubDate>
      <dc:creator>thatdude333</dc:creator>
      <guid isPermaLink="false">21478@/two/discussions</guid>
      <description><![CDATA[<p>Hello all,</p>

<p>I have a couple servos hooked up to an <a rel="nofollow" href="https://www.adafruit.com/product/2327">Adafruit 16-Channel PWM/Servo HAT</a> on a Raspberry Pi 3 that I would like to control via Processing.  Adafruit provides a <a rel="nofollow" href="https://github.com/adafruit/Adafruit_Python_PCA9685">python library</a> that allows easy control of the connected servos via python commands like "setPWM(self, channel, on, off)".  I can control the servos fine from the command line or python script, but have no clue how to execute these inside Processing.  Any help would be much appreciated!</p>
]]></description>
   </item>
   <item>
      <title>Adafruit Keypad and audiofiles</title>
      <link>https://forum.processing.org/two/discussion/21003/adafruit-keypad-and-audiofiles</link>
      <pubDate>Sat, 25 Feb 2017 11:42:22 +0000</pubDate>
      <dc:creator>Bservo</dc:creator>
      <guid isPermaLink="false">21003@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys!</p>

<p>I have a Adafruit 4x3 matrix telephone keypad, which is already connected to an arduino mega and working. On top of that I have soldered an MP3 shield. When the years 1980 until 2016 are pressed, a certain audio file is played. This is all working. Now I want to implement different other audios, for example when you press the star or hash key. Or a constant dial tone in the background, which stops when a certain year is being pressed.</p>

<p>Can anyone help me with that?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Error, disabling serialEvent() for /dev/ttyUSB0 null</title>
      <link>https://forum.processing.org/two/discussion/20939/error-disabling-serialevent-for-dev-ttyusb0-null</link>
      <pubDate>Wed, 22 Feb 2017 02:32:10 +0000</pubDate>
      <dc:creator>jiapei100</dc:creator>
      <guid isPermaLink="false">20939@/two/discussions</guid>
      <description><![CDATA[<p>Looks like Processing is NOT quite stable?
I'm working under Ubuntu 16.04 with an Arduino, and tesing a BNO055 with the tutorial here:
<a rel="nofollow" href="https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/wiring-and-test">https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/wiring-and-test</a></p>

<p>However, it seems I met the error message as titled frequently...
<strong>Error, disabling serialEvent() for /dev/ttyUSB0 null</strong></p>

<p>Any suggestions?</p>
]]></description>
   </item>
   <item>
      <title>Adafruit DotStar</title>
      <link>https://forum.processing.org/two/discussion/17076/adafruit-dotstar</link>
      <pubDate>Thu, 09 Jun 2016 23:29:50 +0000</pubDate>
      <dc:creator>cv_</dc:creator>
      <guid isPermaLink="false">17076@/two/discussions</guid>
      <description><![CDATA[<p>Hey!</p>

<p>I have bought a bunch of APA102C led strips (what adafruit brands as dotstar) and I am looking to control it with processing running on a raspberry pi.</p>

<p>I have been looking into how to make this work (basically using my strips as a screen) and it seems to me the best would be to use the current adafruit which is written in C. Is there a way for me to use this with processing?</p>

<p>This is potentially a silly question but I am thankful for your help,</p>
]]></description>
   </item>
   <item>
      <title>How read an analog input</title>
      <link>https://forum.processing.org/two/discussion/16681/how-read-an-analog-input</link>
      <pubDate>Wed, 18 May 2016 15:20:29 +0000</pubDate>
      <dc:creator>dheld</dc:creator>
      <guid isPermaLink="false">16681@/two/discussions</guid>
      <description><![CDATA[<p>I'd like to write a sketch on a Raspberry Pi in Processing that will take an analog input, say from a knob, that can be read.I've referenced Adafruit's wiring and coding <a rel="nofollow" href="https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi/script">example</a> in Python, but would like to use Processing (without using serial communications from an Arduino. Can anyone help?</p>

<p>Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>Example code: Controlling Electric Motors with a controlP5 knob and Adafruit Motor Shield boards</title>
      <link>https://forum.processing.org/two/discussion/14006/example-code-controlling-electric-motors-with-a-controlp5-knob-and-adafruit-motor-shield-boards</link>
      <pubDate>Tue, 15 Dec 2015 22:50:30 +0000</pubDate>
      <dc:creator>3toedshewie</dc:creator>
      <guid isPermaLink="false">14006@/two/discussions</guid>
      <description><![CDATA[<p>I Wanted to post this code to help out others trying to do something similar.<br />
you need to have the controlP5 and Adafruit libraries installed. I hope my notes are helpful.</p>

<p>the code is a combination of the following codes:<br />
    1) <a href="https://processing.org/tutorials/electronics/" target="_blank" rel="nofollow">https://processing.org/tutorials/electronics/</a>  (Example 5A and 5B)<br />
    2) <a href="https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/using-dc-motors" target="_blank" rel="nofollow">https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/using-dc-motors</a><br />
    3) <a href="http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5knob/ControlP5knob.pde" target="_blank" rel="nofollow">http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5knob/ControlP5knob.pde</a></p>

<p>Processing:<br />
    // Write data to the serial port according to the status of a ControlP5 Knob controlled<br />
    // by the mouse. uses values from 0-255.</p>

<pre><code>import processing.serial.*;
import controlP5.*; // import library for knob

Serial port;        // Create serial port object 
ControlP5 cp5;      // defines the type "cp5" as a variable "type" defined in ControlP5  for knob

int myColorBackground = color(0,0,0);  
int knobValue = 100;  

Knob myKnobA;  
Knob myKnobB;  

void setup() {

  port = new Serial(this, 9600); 
  size(700,400);  
  smooth();  
  noStroke(); 

  cp5 = new ControlP5(this);  //object created from library (what is this exactly?)  

  myKnobA = cp5.addKnob("knob")  // "method" is add(ControllerInterface&lt;?&gt; theElement) 
               .setRange(0,255) 
               .setValue(50)  
               .setPosition(100,70)  
               .setRadius(50)  // for knob
               .setDragDirection(Knob.VERTICAL)  
               ;                  
} 

void draw() {   

  background(myColorBackground); 
  fill(knobValue);   
  rect(0,height/2,width,height/2);   
  fill(0,100);   
  rect(80,40,140,320);  
} 

void knob(int theValue) {   
  myColorBackground = color(theValue);  
  println("a knob event. setting background to "+theValue); 
  port.write(theValue); 
}  
</code></pre>

<p>Arduino: 
    // Read data from the serial and turn a DC motor on or off according to the value. with adafruit motor driver 
    // board code included</p>

<pre><code>#include &lt;Wire.h&gt;     
#include &lt;Adafruit_MotorShield.h&gt; 
#include "utility/Adafruit_PWMServoDriver.h"  

// Create the motor shield object with the default I2C address   
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// DONT USE THIS ONE IF RUNNING MULIPLE MOTORS   
// Or, create it with a different I2C address (say for stacking)   
Adafruit_MotorShield AFMS = Adafruit_MotorShield(0X60);  // 1st board if stacking 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1); // 1st board, M1 

char val;             // Data received from the serial port

void setup() { 
  Serial.begin(9600);                  // Start serial communication at 9600 bps 

  AFMS.begin();  // create with the default frequency 1.6KHz, this connects to the 
             // controller- need one for each motor? nope.  
} 

void loop() { 
  if (Serial.available()) {            // If data is available,  
    val = Serial.read();               // read it and store it in val 
  } 
  myMotor1-&gt;setSpeed(val); 
  myMotor1-&gt;run(FORWARD); 
  delay(100);                          // Wait 100 milliseconds for next reading
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can i use Keypressed instead of mouse position in processing to work with arduino?</title>
      <link>https://forum.processing.org/two/discussion/13532/how-can-i-use-keypressed-instead-of-mouse-position-in-processing-to-work-with-arduino</link>
      <pubDate>Mon, 16 Nov 2015 04:24:39 +0000</pubDate>
      <dc:creator>nsch6510</dc:creator>
      <guid isPermaLink="false">13532@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
so this is my code so far and all works well. However i would like to use 3 hotkeys to change the colour than mouse position.</p>

<p>Anyone know how i can do this?</p>

<p>Thanks</p>

<blockquote class="Quote">
  <p>Processing code</p>
</blockquote>

<pre><code>   import processing.serial.*;
   Serial port;
   int c;

   void setup() {
     size(300, 150);
    // println("Available serial ports:");
    // println(Serial.list());
    port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
    c = 2;
   }

  void draw() {
  background(255);
  line(100, 0, 100, height);
  line(200, 0, 200, height);
   // write the current X-position of the mouse to the serial port as
  // a single byte

 int newc = int(1 + mouseX/100);
 if (newc != c) {
 c = newc; 

println("&gt;&gt; " + c); // DEBUG
port.write("" + c);
 }
}
</code></pre>

<blockquote class="Quote">
  <p>Arduino code</p>
</blockquote>

<pre><code>   #include &lt;Adafruit_GFX.h&gt;    // Core graphics library
   #include &lt;Adafruit_ST7735.h&gt; // Hardware-specific library
   #include &lt;SPI.h&gt;

   #define TFT_CS     10
   #define TFT_RST    9
   #define TFT_DC     8
   #define TFT_SCLK 13
   #define TFT_MOSI 11

   Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

   void setup(void) {
     Serial.begin(9600);
     tft.initR(INITR_144GREENTAB);   
     tft.fillScreen(ST7735_BLACK);
     Serial.println("OK!");
   }

   void loop() {
     tft.invertDisplay(false);
     if (Serial.available()) {
       byte c = Serial.read();
       if (c == '1') {
         testdrawrects(ST7735_GREEN);
       } else if (c == '2') {
         testdrawrects(ST7735_WHITE);      
       } else if (c == '3') {
         testdrawrects(ST7735_RED);
       }
       Serial.println(c); // DEBUG
     }
   }

   void testdrawrects(uint16_t color) {
     // tft.fillScreen(ST7735_BLACK);
     for (int16_t x=0; x &lt; tft.width(); x+=6) {
       tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
     }
   }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Motor not running</title>
      <link>https://forum.processing.org/two/discussion/11819/motor-not-running</link>
      <pubDate>Thu, 23 Jul 2015 23:11:51 +0000</pubDate>
      <dc:creator>dahaka919</dc:creator>
      <guid isPermaLink="false">11819@/two/discussions</guid>
      <description><![CDATA[<p>I am using controlP5 on processing to make a GUI that runs a dc motor on Arduino. The GUI asks for the velocity, time for the motor to run, and the direction and stores them in variables. When the start button is hit it is suppose to send the data to the Arduino. The problem is that the motor is not running. I put some println commands in the processing code to figure out where it stops but all the println commands work. I don't know if it is a problem with the Arduino code or if it is not sending the data.</p>

<p><strong>Processing Code</strong></p>

<pre><code>import processing.serial.*;
import controlP5.*;

Serial myPort;
ControlP5 cp5;
DropdownList serialPortsList;
Serial serialPort;
final int BAUD_RATE=9600;
ControlTimer c;
Textlabel t;
Textlabel txtlblwhichcom;
Textarea commTextarea;
ListBox commListbox;
Serial[] myPorts=new Serial[1];

int col=color(255);
int segment=4;
String val[];
long current;
long previous;
long timePassed;
String timeMillis;
PrintWriter output;
String photo;
String [] var=new String[4];
String vel;
String time="0";
int timeMeasure;
String dir;
String onOff="0";
int onOffMeasure;
String fileName;
String fileN;
String textValue="";
boolean firstContact=false;
RadioButton rb;

void setup(){
  myPort=new Serial(this, Serial.list()[3], 9600);
  myPort.bufferUntil('\n');
  size(700,500);
  PFont font=createFont("arial", 20);
  String[] portNames=Serial.list();
  cp5=new ControlP5(this);
  serialPortsList=cp5.addDropdownList("Serial ports").setPosition(10,10).setWidth(200);
  for(int i=0;i&lt;portNames.length;i++) serialPortsList.addItem(portNames[i],i);

  c=new ControlTimer();
  t=new Textlabel(cp5,"--",100,100);
  c.setSpeedOfTime(1);

  cp5.addCheckBox("checkBox")
    .setPosition(250, 330)
    //.setColorBackground(color(255,13,227))
    .setColorForeground(color(120))
    .setColorActive(color(255))
    .setColorLabel(color(255))
    .setSize(40, 40)
    .setItemsPerRow(3)
    .setSpacingColumn(100)
    .setSpacingRow(20)
    .addItem("Photogate 1", 0)
    .addItem("Photogate 2", 50);

  cp5.addTextfield("Belt Velocity (mm/s)")
     .setPosition(20,90)
     .setSize(200,40)
     .setFont(font)
     .setFocus(true)
     .setColor(color(255,0,0))
     ;

  cp5.addTextfield("Run Time (s)")
     .setPosition(20,160)
     .setSize(200,40)
     .setFont(font)
     .setFocus(false)
     .setColor(color(255,0,0))
     ;

  cp5.addTextfield("Text File Name")
     .setPosition(20,230)
     .setSize(200,40)
     .setFont(font)
     .setFocus(false)
     .setColor(color(255,0,0))
     ;           

  cp5.addButton("Enter")
     .setValue(0)
     .setPosition(240,90)
     .setSize(80,40)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;

 cp5.addButton("ENTER")
     .setValue(0)
     .setPosition(240,160)
     .setSize(80,40)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;

 cp5.addButton("EnteR")
     .setValue(0)
     .setPosition(240,230)
     .setSize(80,40)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;    

  cp5.addButton("Start")
     .setValue(0)
     .setPosition(120,410)
     .setSize(80,40)
     .setColorBackground(color(9,158,12))
     .setColorLabel(color(0,0,0))
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;

  cp5.addButton("Stop")
     .setValue(0)
     .setPosition(480,410)
     .setSize(80,40)
     .setColorBackground(color(168,8,8))
     .setColorLabel(color(0,0,0))
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;

  rb = cp5.addRadioButton("radioButton")
         .setPosition(480,100)
         .setSize(90,40)
         .setColorForeground(color(120))
         .setColorActive(color(255))
         .setColorLabel(color(255))
         .setItemsPerRow(1)
         .setSpacingColumn(50)
         .addItem("Clockwise",1)
         .addItem("Counter-ClockWise",2)
         ;
  textFont(font);
}

void draw(){
  current=millis();
  background(0);
  fill(255);
  t.setValue(c.toString());
  t.draw(this);
  t.setPosition(480,50);

  if(segment==0){
    var[0]=vel;
    var[1]=time;
    var[2]=dir;
    var[3]=onOff;
    timeMeasure=Integer.parseInt(time);
    onOffMeasure=Integer.parseInt(time);
    println("segment 1 end");
    segment=1;
  }
  else if(segment==1){
    for(int x=0;x&lt;4;x++){
      myPort.write(var[x]);
      print("sent ");
      println(var[x]);
    }

    segment=2;
    previous=current;
    output=createWriter(fileName);
    println("wrote file");
  }
  else if(segment==2){
    if(myPort.available()&gt;0){
      photo=myPort.readStringUntil('\n');
      output.print(photo);
      timePassed=current-previous;
      timeMillis=str(timePassed);
      output.println(timeMillis);
    }

    if((current-previous)&gt;=(timeMeasure*1000)){
      segment=3;
      onOff="0";
      println("segment 2 finished");
    }
  }
  else if(segment==3){
    var[0]="0";
    var[1]="0";
    var[2]="0";
    var[3]=onOff;

    for(int x=0;x&lt;4;x++){
      myPort.write(var[x]);
    }

    output.flush();
    output.close();

    segment=4;
    println("segment 3 finished");
  }
  else{
    segment=4;
    //println("fish");
  }
}

public void Enter(){
  vel=cp5.get(Textfield.class,"Belt Velocity (mm/s)").getText();
  println("Got Velocity");
}

public void ENTER(){
  time=cp5.get(Textfield.class,"Run Time (s)").getText();
  println("Got Time");
}

public void EnteR(){
  fileN=cp5.get(Textfield.class,"Text File Name").getText();
  fileName=fileN+".txt";
  println("Got filename");
}

void radioButton(int a) {
  dir=str(a);
  println("a radio Button event: "+a);
}

public void Start(){
  /*if(mousePressed){
    segment=0;
    println("Mouse Working");
  }*/
  if(current&gt;100){
    println("if statement Working");
    segment=0;
    onOff="1";
  }
}

public void Stop(){
  if(current&gt;100){
    segment=3;
    onOff="0";
 }


}

void controlEvent(ControlEvent theEvent){
  if(theEvent.isGroup()){
    if(serialPort !=null){
      serialPort.stop();
      serialPort=null;
    }

    String portName=serialPortsList.getItem((int)theEvent.getValue()).getName();
    try{
      serialPort=new Serial(this,portName,BAUD_RATE);
    }
    catch(Exception e){
    }
  }
}
</code></pre>

<p>Arduino Code</p>

<pre><code>#include &lt;Wire.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;Adafruit_MotorShield.h&gt;
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS=Adafruit_MotorShield();

Adafruit_DCMotor *myMotor=AFMS.getMotor(3);

unsigned long Timems=0;
unsigned long Timeus=0;
int Photogate1=HIGH;
int Photogate2=HIGH;
int PhotogatePin1=10;
int PhotogatePin2=12;
int motorPin=3;
float onOff=0;
float var[4];
int index=0;
float volt;
float direct;
long previous;
float vel;
float time;

void setup(){
  Serial.begin(9600);
  AFMS.begin();
  pinMode(motorPin, OUTPUT);
}

void loop(){
  unsigned long current=millis();

  if(onOff==0){
     if (Serial.available()){
       float incomingValue=Serial.parseFloat();
       var[index]=incomingValue;
       index++;
     }

     if(var[3]==1){
       onOff=var[3];
       previous=current;
     }
  }
  else if(onOff==1){
    vel=var[0];
    time=var[1]*1000;
    direct=var[2];
    volt=vel;
    index=0;

    if(direct==1){
      myMotor-&gt;run(FORWARD);
    }
    if(direct==2){
      myMotor-&gt;run(BACKWARD);
    }

    onOff=2;
  }
  else if(onOff==2){
    myMotor-&gt;setSpeed(volt);

  /*  Photogate1=digitalRead(PhotogatePin1);
    Photogate2=digitalRead(PhotogatePin2);

    if(Photogate1==LOW){
      Timems=millis();
      Timeus=micros();

      Serial.println("Photogate 1");

      delay(100);
    }
    else if(Photogate2==LOW){
      Timems=millis();
      Timeus=micros();

      Serial.println("Photogate 2");

      delay(100);
    }
    else{
      digitalWrite(Photogate1, HIGH);
      digitalWrite(Photogate2, HIGH);
    }
  }   */
    if(Serial.available()){
      float incomingValue=Serial.parseFloat();
      var[index]=incomingValue;
      index++;
    }

    if(var[3]==0){
      onOff=3;
    }
  }
  else{
    vel=var[0];
    time=var[1]*1000;
    direct=var[2];
    onOff=var[3];
    volt=vel;
    index=0;
  }
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>