Documente Academic
Documente Profesional
Documente Cultură
Source Code :
Arduino
float temp;
int tempPin = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.println(temp);
delay(1000);
}
Processing
import processing.serial.*; fill(255,255,255);
Serial commPort; rect(410,10, 100, 300);
float tempC; }
float tempF; else if (num <= 25 && num >= 21 ){
String myString = null; fill(255,255,255);
float num; rect(10,10, 100, 300);
fill(255,255,0);
void setup() rect(210,10, 100, 300);
{ fill(255,255,255);
size(600,400); rect(410,10, 100, 300);
commPort = new Serial(this, "COM10", }
9600); else if (num < 21){
} fill(255,255,255);
rect(10,10, 100, 300);
void draw(){ fill(255,255,255);
while (commPort.available() > 0) { rect(210,10, 100, 300);
myString = fill(0,255,0);
commPort.readStringUntil(10);
rect(410,10, 100, 300);
if (myString != null) {
num=float(myString);
}
if (num > 25){
}
fill(255,0,0);
}
rect(10,10, 100, 300);
}
fill(255,255,255);
rect(210,10, 100, 300);
Output
\
2. Rangkaian
File notepad :
Source Code
Arduino
void setup() {
pinMode(2, OUTPUT); //Turn off all LEDs if the byte Read = 0
pinMode(3, OUTPUT); if(byteRead==0){
pinMode(4, OUTPUT); //Turn off all LEDS
pinMode(5, OUTPUT); digitalWrite(2, LOW);
pinMode(6, OUTPUT); digitalWrite(3, LOW);
pinMode(7, OUTPUT); digitalWrite(4, LOW);
pinMode(8, OUTPUT); digitalWrite(5, LOW);
pinMode(9, OUTPUT); digitalWrite(6, LOW);
pinMode(10, OUTPUT); digitalWrite(7, LOW);
Serial.begin(9600); digitalWrite(8, LOW);
} digitalWrite(9, LOW);
digitalWrite(10, LOW);
void loop() { }
byte byteRead;
if(byteRead>0){
if (Serial.available()) { digitalWrite((byteRead+1), HIGH); // set
the LED on
byteRead = Serial.read();
}
//You have to subtract '0' from the read Byte
to convert from text to a number. }
byteRead=byteRead-'0'; }
Processing
import processing.serial.*; //This is turned off when mySwitch = 0
import java.io.*; mySwitch=1;
int mySwitch=0;
int counter=0; //Open the serial port for communication
with the Arduino
String [] subtext;
//Make sure the COM port is correct
Serial myPort;
myPort = new Serial(this, "COM10", 9600);
myPort.bufferUntil('\n');
}
void setup(){
//Create a switch that will control the
frequency of text file reads. void draw() {
//When mySwitch=1, the program is setup if (mySwitch>0){
to read the text file.
/*The readData function can be found later
in the code. /* The following function will read from a
This is the call to read a CSV file on the CSV or TXT file */
computer hard-drive. */ void readData(String myFileName){
readData("D:lampu.txt");
Source Code:
Arduino
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {