Sending data from Processing to Arduino
(Redirected from Writing-fromProcessing-toArduino)
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Processing write to serial port
1import processing.serial.*;
2static final int PORT_INDEX=6,BAUDS=9600;
3Serial myPort;
4//Serial myPort;
5void setup()
6{
7 size(400,400);
8 final String[] ports = Serial.list();
9 printArray(ports);
10 myPort =new Serial(this, ports[PORT_INDEX], BAUDS);
11}
12
13void draw(){
14if(mousePressed ==true){
15myPort.write('1');
16}else{
17myPort.write('0');
18}
19}
Arduino recive from serial port
1#include <Adafruit_CircuitPlayground.h>
2char val;
3void setup(){
4 Serial.begin(9600);
5 CircuitPlayground.begin();
6 }
7void loop(){
8 CircuitPlayground.clearPixels();
9 if (Serial.available()){
10 val= Serial.read();
11 }
12 if(val=='1'){
13 for (int i=0;i<10;i++){
14 if (i!=0 && i!=2 && i!=4){
15 CircuitPlayground.setPixelColor(i, 255, 0, 0);
16 }
17 }
18 delay(20);
19 }
20 if(val==0){
21 CircuitPlayground.clearPixels(); }
22 delay(10);
23}