Difference between revisions of "Sending data from Processing to Arduino"
Jump to navigation
Jump to search
(Created page with " ===Processing write to serial port=== <syntaxhighlight lang="java" line='line'> import processing.serial.*; static final int PORT_INDEX=6,BAUDS=9600; Serial myPort; //Serial...") |
|||
Line 53: | Line 53: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | [[Category:Arduino]][[Category:Processing]] |
Revision as of 10:26, 18 November 2022
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}