For this assignment I thinked to implement the Interface for networking assignment.
The idea is can to monitoring the Master Data, in other words, on the Interface the user can see the button state, error state and can modify the led state of each slave.
For this I decided to write the application in Processing 3.0.2
In input devices assignment I learnt to writte applications in Processing.
import processing.serial.*; // import serial comunication
Serial serial; // create an Serial object
PFont f1, f2, f3;
// initialice slaves variables
char led2=0, led1=0, button2=0, button1=0, error2=0, error1=0;
void setup(){
size(435, 400); // define the screen size
// open first serial port at 115200 baud
serial = new Serial(this, Serial.list()[0], 115200);
f1 = createFont("Arial", 18, true);
f2 = createFont("ACaslonPro-BoldItalic", 14, true);
f3 = createFont("Arial", 12, true);
}
void draw(){
sendData(); // send Leds data to master
if(updateSerial() == 1){ // receive data from master
background(245); // reset screen
stroke(175);
line(0, 0, width, 0);
textFont(f1, 18);
fill(0);
textAlign(CENTER);
text("I2C MASTER MONITORING", width/2, 25);
stroke(175);
line(0, 36, width, 36);
stroke(175);
line(width/2, 36, width/2, height);
textFont(f1, 14);
fill(0);
textAlign(CENTER);
text("Slave 1", width*1/4, 67);
textFont(f1, 14);
fill(0);
textAlign(CENTER);
text("Slave 2", width*3/4, 67);
textFont(f2, 12);
textAlign(CENTER);
rectMode(CENTER);
stroke(75);
// paint led button of slave 1
if(led1 == '1') fill(255,250,25);
else fill(255);
rect(width*1/4, 130, 100, 60, 10);
if(led1 == '1') fill(255);
else fill(255,175,0);
text("LED", width*1/4, 134);
// paint led button of slave 2
if(led2 == '1') fill(255,250,25);
else fill(255);
rect(width*3/4, 130, 100, 60, 10);
if(led2 == '1') fill(255);
else fill(255,175,0);
text("LED", width*3/4, 134);
// paint button of slave 1
if(button1 == '1') fill(0,175,255);
else fill(255);
rect(width*1/4, 230, 100, 60, 10);
if(button1 == '1') fill(255);
else fill(0,0,255);
text("BUTTON", width*1/4, 234);
// paint button of slave 2
if(button2 == '1') fill(0,175,255);
else fill(255);
rect(width*3/4, 230, 100, 60, 10);
if(button2 == '1') fill(255);
else fill(0,0,255);
text("BUTTON", width*3/4, 234);
// paint error button of slave 1
if(error1 != 0) fill(255,50,0);
else fill(255);
rect(width*1/4, 330, 100, 60, 10);
if(error1 != 0) fill(255);
else fill(255,0,0);
text("ERROR", width*1/4, 334);
// paint error of slave 2
if(error2 != 0) fill(255,50,0);
else if(error2 == 0) fill(255);
rect(width*3/4, 330, 100, 60, 10);
if(error2 != 0) fill(255);
else fill(255,0,0);
text("ERROR", width*3/4, 334);
}
}
int updateSerial(){
// receive data until end line character
String data = serial.readStringUntil('\n');
if(data != null){
// separate and assign each data
String[] values = split(data, " ");
if(values.length == 7){
button1 = values[0].charAt(0);
led1 = values[1].charAt(0);
error1 = values[2].charAt(0);
button2 = values[3].charAt(0);
led2 = values[4].charAt(0);
error2 = values[5].charAt(0);
}
return 1;
}
else return 0;
}
public void sendData(){
// check mouse position
if(mousePressed){
if((mouseX>width*1/4-50)&&(mouseX<width*1/4+50)&&(mouseY>130-30)&&(mouseY<130+30)){
serial.write("a1");
}
else if((mouseX>width*3/4-50)&&(mouseX<width*3/4+50)&&(mouseY>130-30)&&(mouseY<130+30)){
serial.write("b1");
}
}
else{
serial.write("a0");
serial.write("b0");
}
}
In next picture you can see the Interface.
In the past I made many HMIs in some tools for example:
LabView is a graphical programming and I think that is the most easy software for Interface programming, but is a liscenced tool.
JAVA is more difficult to made application but is free.
I prefer Processing becouse is based in JAVA (free) and has an extensive community to find libraries.
Interface and Application Programming files :
- Interface in Processing (.pde) : https://archive.fabacademy.org/...
- Interface in LabView (.vi) : https://archive.fabacademy.org/...
- Interface in JAVA (.rar) : https://archive.fabacademy.org/...
- Interface in C# (.rar) : https://archive.fabacademy.org/...