A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://howtomechatronics.com/tutorials/arduino/processing/ below:

Arduino Tutorial 06: Processing - How To Mechatronics

Welcome to the sixth Arduino Tutorial from our Arduino Tutorial Series. In this tutorial we will learn how to connect Arduino to Processing and how are they communicatng using the Serial Port. Also we will make an example where we will use the Processing IDE to send commands to the Arduino Board and vice-verse.

This is a Step by Step Video Tutorial which is easy to be followed. Also, below the video you can find what Parts do we need for this tutorial and the Source Codes of the Examples in the video.

Components needed for this Arduino Tutorial

You can get the components from any of the sites below:

Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.

Circuit Schematic Arduino Source Code
int led = 13;
int button = 12;

void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT);
Serial.begin(9600);
}

void loop(){
if(Serial.available() > 0) {
char ledState = Serial.read();
if(ledState == '1'){
digitalWrite(led, HIGH);
}
if(ledState == '0'){
digitalWrite(led, LOW);
}
}
int buttonState = digitalRead(button);
if ( buttonState == HIGH){
Serial.println("Button is pressed");
delay(500);
}
}Code language: JavaScript (javascript)
Processing Source Code
import processing.serial.*;

Serial myPort;
String myText="";

void setup(){
size(300, 300);
myPort = new Serial(this, "COM4", 9600);
myPort.bufferUntil('n');
}
void serialEvent (Serial myPort){
myText = myPort.readStringUntil('n');
}

void draw(){
background(0,0,0);
text(myText, 120, 120);
myText="";

if(mousePressed && (mouseButton == LEFT)){
myPort.write('1');
}
if (mousePressed && (mouseButton == RIGHT)){
myPort.write('0');
}
}Code language: JavaScript (javascript)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4