1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Processing and arduino workshop material ( PDFDrive com ) pdf

583 256 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Environment Environment-Toolbar Buttons The toolbar buttons allow you to run and stop programs, create new sketches, open, save and export: Run Compiles the code, opens a display window, and runs the program inside Stop Terminates a running program, but does not close the display window New Creates a new sketch Open Provides a menu with options to open files Another way of opening files is dragging and the file icon to text editor area or processing icon Save Saves the current sketch to its current location Export Exports the current sketch as a Java applet embedded in an HTML file Your First Piece of Code void setup(){ size(200,200); } void draw(){ background(125); float x=mouseX; float y=mouseY; println("Mouse x=" + x + " Mouse y=" + y); line (x,y,100,100); } Environment-Menu Bar The menus provide the same functionality as the tool bar in addition to actions for file management and opening reference materials Environment-Menu Bar-Default Examples Under Examples you can find already made codes that you can use as the base of your experiments and achieve the desired result by changing these base codes This is what programmers call hacking Meaning that you not start a piece of software yourself You use other’s software and change parts of it, to make it work your way Hacking the Default Examples For example lets go to examples , under basic, under transform, choose arm, and run the code Hacking the Default Examples Let’s say we want the background color white and we want to double the size of the applet Hacking the Default Examples size(400,400); Hacking the Default Examples background(255); Hacking the Default Examples Your code Preexisting Code Hacking the code Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input 10 Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input 11 Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input 12 Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input 13 Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input 14 Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input 15 Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input First Arduino Connects to The first Processing Using Serial Port Serial.begin(9600);//Open Serial Port Serial.println(in);//Sending Data via Serial Port First Processing Function as a Server Connecting To the Second Processing via Net, Reading Data from Arduino Using Serial Port and Sending Data to Client Processing Using Net import processing.net.*;//Importing the net library to Connect to Second Processing and Send Data to it import processing.serial.*;//Importing serial Library to Connect to Arduino and Read from It Server myServer;//Initiating a Server to Send data to Client via net Serial port;//Initiating a Serial Port to Receive Data from Arduino myServer = new Server(this, InternetPort); //Connect to Internet by Starting myServer on port 5204 port = new Serial(this, Serial.list()[1], 9600); //Connect to Arduino Use the first available port myServer.write(Value);//Send data to the client Processing via Net Second Processing Functions as a Client Connecting to the First Processing via Net, Reading Data from Server Processing Using Net and Sending Data to the Second Arduino Using Serial Port import processing.net.*; import processing.serial.*; Serial myPort; //Innitiate a Serial Port Client myClient; //Innitiate a Client myClient = new Client(this, ipAddress , 5204); //Begin Client Connection to Server myPort = new Serial(this, Serial.list()[8], 9600);//Begin Serial Port inString = myClient.readString();//Receive Data from Server via Net myPort.write(int(inString));//Send Data to Arduino via Serial Port Second Arduino Connects to Client Processing and Read Data from it via Serial Port Serial.begin(9600);//Open Serial Connection val = Serial.read();//Read Data from Serial Port 16 Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input 17 (Client and Server on Different Computers) Tele-presence – Connecting Two Processing Platforms via Internet Controlling Arduino Output based on Distant Arduino Input vs (Client and Server on the Same Computer) Synchronized Input/OutputActuating the Physical Space and Monitoring the Physical Properties of the Space at the same time 18 Master Things that Talk to Eachother Connecting Two Arduino Together Slave Master Arduino Can control the Slave Arduino by Sending Data to it Thus it is better to connect the devices that monitor the space and sense the changes in the physical properties of the space to the Master one and connect the Actoators of the space that are activated based on sensed changes in physical properties of the space to the Slave one Master/Slave connection is one way if you are short in digital or analog pins and have more sensors and actoators than the pins that are available on one Arduino 19 Things that Talk to Eachother Hardware Serial Connection on TX and RX 20 Things that Talk to Eachother Hardware Serial Connection on TX and RX //Master void setup(){ Serial.begin(9600); pinMode(13,OUTPUT); } void loop(){ digitalWrite(13,HIGH); Serial.println(0); delay(1000); digitalWrite(13,LOW); Serial.println(1); delay(1000); } //Slave void setup(){ Serial.begin(9600); pinMode(13,OUTPUT); } void loop(){ int in=Serial.read(); if (in==48){ digitalWrite(13,HIGH); } if(in==49){ digitalWrite(13,LOW); } } 21 Things that Talk to Each other Software Connection on pin2 and pin3 22 Things that Talk to Each other Software Connection on pin2 and pin3 // this is the code for the arduino board which is the master // the master can control the slave arduino board if connected to it // through hardware serial port tx1 and rx0 or software serial ports // which are introduced with softwareserial library // in this program we are transforming digital pin and to serial transmitter and reciever // connect this arduino to the other arduino via digital pin and // pin of master arduino board is connected to pin of the slave arduino board // pin of master arduino board is connected to pin of the slave arduino board #include #define rxPin #define txPin SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); void setup(){ pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode(13,OUTPUT); Serial.begin(9600); mySerial.begin(9600); } void loop(){ if(millis()%20001000){ digitalWrite(13,LOW); mySerial.println(1); } } // this is the code for slave board // connect the slave board to the master board via digital pin and // on slave to on master and on slave to on master #include #define rxPin #define txPin SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); void setup(){ pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode(13,OUTPUT); Serial.begin(9600); mySerial.begin(9600); } void loop(){ char in=mySerial.read(); Serial.println(in); if (in==48){ digitalWrite(13,HIGH); } if(in==49){ digitalWrite(13,LOW); } } 23 Things that Talk to Eachother Multiple Software Connections 24 ... Piece of Code void setup () { size(200,20 0); } void draw () { background(12 5); float x=mouseX; float y=mouseY; println("Mouse x=" + x + " Mouse y=" + y); line (x,y,100,10 0); } Environment-Menu Bar... values with operators such as > (greater than) and < (less than) These comparisons are evaluated as true or false Expression Value 5 122.3+3.1 125.4 (( 3+ 2)* -1 0) + -46 6>3 true 54 < 50 false ... window in range of (black) to 255 (white) */ background(10 2); Processing- Syntax-Functions Comment // The size function has two parameters: width and height size(200,20 0); Function Parameter Statement

Ngày đăng: 16/12/2019, 15:48

Xem thêm:

TỪ KHÓA LIÊN QUAN

Mục lục

    Your First Piece of Code

    Hacking the Default Examples

    Hacking the Default Examples

    Hacking the Default Examples

    Hacking the Default Examples

    Hacking the Default Examples

    Exporting as a Java Applet on a Webpage

    Exporting as a Java Applet on a Webpage

    Exporting as a Java Applet on a Webpage

    Exporting as a Java Applet on a Webpage

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN