我是一名学生和另外15人一起住在学生宿舍。我正在尝试建立一个出勤系统,该系统将显示在家中和不在家的屏幕上。我认为给每个人一个RFID标签是一个很好的计划,所以当他们回家或离开时他们可以办理入住和退房手续。这将显示在显示绿色或红色圆圈的屏幕上(使用处理)。
我使用了https://www.youtube.com/channel/UC6LO26f_9qwysjvSHdVmfrQ和https://github.com/InfinityWorldHI/RFID_Excel的部分代码来获取arduino代码。
我只为前两个室友编程处理。但是,当入住或退房时,两个圆圈都会改变颜色。我想有两排8个圆圈,可以从红色变为绿色,另一个方向可以看看是否有人在家。
我的arduino程序输出房间号码“,”1或0(如签入或签出)输出例如= 11,1。
处理程序将根据签入或签出绘制绿色或红色圆圈。
这是我的处理代码:
Arduino代码(输出到串口的地方):
if(NumbCard[j] == 1 && statu[s] == 0 && Number == 11) {
statu[s]=1;
NumbCard[j]=0;
Serial.print(Number);
Serial.print(",");
Serial.println(1);
//Serial.println("is uitgecheckt");
//write led uit
}
else if(NumbCard[j] == 1 && statu[s] == 0 && Number == 22) {
statu[s]=1;
NumbCard[j]=0;
Serial.print(Number);
Serial.print(",");
Serial.println(1);
//Serial.println("is uitgecheckt");
//write led uit
}
处理代码以制作圈子:
import processing.serial.*;
// ControlP5 Example 1 : Basic UI elements
import controlP5.*; // import controlP5 library
ControlP5 controlP5; // controlP5 object
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
int end = 10; // Linefeed in ASCII
String myString = null;
int i =0;
PShape led_on, led_off;
String persoon_status;
color [] colors = new color[2];
void setup() {
colors[0] = color(0,255,0);
colors[1] = color(255,0,0);
//change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial (this, Serial.list()[0], 9600);
//led_on = createShape(RECT,10,70,40,40,40);
size(800,800);
}
void draw() {
background(255);
do{
myString = myPort.readStringUntil(end);
if (myString != null) {
println(myString);
}
}
while (myPort.available() > 0); {
if(myString != null && myString.trim().equals("11,1") == true) {
fill(colors[1]);
} else {
if (myString != null && myString.trim().equals("11,0") == true)
fill(colors[0]);
else{
rect(10,70,40,40,40);
}
}
if(myString != null && myString.trim().equals("22,1") == true){
fill(colors[1]);
} else {
if(myString != null && myString.trim().equals("22,0") == true)
fill(colors[0]);
else {
rect(10,130,40,40,40);
}
}
}
}
我想我已经接近尾声,但是我无法解决这个问题。
有人能指出我正确的方向吗?
请随时向我询问更多信息。
非常感谢您的帮助!
当您设置fill()
颜色时,从该点绘制的所有形状将具有相同的颜色,直到您使用新颜色设置fill()
。在您的代码中,您只能在读取RFID时更改颜色,否则您只需绘制形状,这意味着它们都具有最后设置的颜色。
相反,您应该使用数组来存储每个室友的状态。然后,您可以循环遍历此数组,并在绘制矩形之前将填充设置为适当的颜色。
此代码段显示了如何实现此功能。
boolean[] isPresent = { false, false};
void draw() {
// put the code that handles the RFID processing in
// a separate function that you call in draw
readRFID();
background(255);
//loop through the array
for (int i = 0; i < isPresent.length; i++) {
//check status and set fill color
if (isPresent[i]) {
fill(colors[0]);
} else {
fill(colors[1]);
}
//draw rectangle with x-pos based on array index
rect(10+i*50, 10, 40, 40);
}
}