電路圖
首先,將LED的正極連接到Raspberry Pi的GPIO4,然后將LED的負極連接到gro Raspberry Pi的引腳通過220歐姆電阻器。
安裝軟件
您需要在Raspberry Pi上安裝處理IDE。在這里下載Linux ARMv6hf的處理。
下載后,將其放入要安裝處理的文件夾中。然后,右鍵單擊它并單擊“在此處提取”?,F在將創建一個名為“處理”的文件夾。右鍵單擊此文件夾,然后選擇“在終端中打開”。終端窗口將打開。在其中鍵入以下命令,處理IDE將打開。
。/processing
現在您需要安裝Wekinator軟件。所以轉到下面的鏈接并點擊“任何操作系統,包括Linux”。
下載后,將其放在要安裝的位置,然后右鍵單擊它,然后單擊“在此處提取”。將創建一個新目錄。右鍵單擊它并選擇“Run in terminal”。在終端中,編寫以下命令,Wekinator將開始運行。
java -jar WekiMini.jar
入門
現在將這篇文章末尾給出的代碼粘貼在兩個單獨的處理草圖中并運行它們。在Wekinator窗口中,進行如下設置。將輸入和輸出設置為1,將類型設置為“所有分類器”,分為2個類。
點擊“下一步”,將打開一個新窗口如下所示。
打開處理窗口,單擊綠色三角形,然后開始錄制半秒鐘。單擊紅色圓圈并將類更改為2(在輸出-1前面)。然后開始錄制半秒鐘。
之后,單擊“訓練”,然后單擊“運行”?,F在,當您點擊綠色三角形時,連接到Raspberry Pi的LED將亮起,當您點擊紅色圓圈時,連接到Raspberry Pi的LED將關閉。
處理代碼(輸入到Wekinator)
// Importing the library which will help us in communicating with the wekinator
import oscP5.*;
import netP5.*;
//creating the instances
OscP5 oscP5;
NetAddress dest;
float bx;
void setup() {
// Size of output window
size(200, 50, P3D);
// Starting the communication with wekinator. listen on port 9000, return messages on port 6448
oscP5 = new OscP5(this,9000);
dest = new NetAddress(“127.0.0.1”,6448);
}
void draw() {
// Creating the boxes in output window
blocks();
// Send the OSC message to wekinator
sendOsc();
}
void mousePressed()
{
// If mouse is pressed in the first box
if (mouseX 》 0 && mouseX 《 50)
{
bx=1;
}
// If mouse is pressed in the second box
if (mouseX 》 100 && mouseX 《 150)
{
bx=2;
}
}
void sendOsc() {
OscMessage msg = new OscMessage(“/wek/inputs”);
msg.add((float)bx);
oscP5.send(msg, dest);
}
void blocks()
{
background(0);
fill(0, 128, 0);
ellipse(25, 25, 50, 50);
fill(255);
text(“ON”, 10, 30);
fill(255, 0, 0);
ellipse(125, 25, 50, 50);
fill(255);
text(“OFF”, 120, 30);
}
處理代碼(Wekinator的輸出)
// Importing the library that will help us in controlling the GPIO pins of raspberry pi
import processing.io.*;
// Importing the library which will help us in communicating with the wekinator
import oscP5.*;
import netP5.*;
// Creating the instances
OscP5 oscP5;
NetAddress dest;
// Variable to store the output
public int output;
void setup()
{
// Setting the GPIO 4 as output pin
GPIO.pinMode(4, GPIO.OUTPUT);
// Starting the communication with wekinator. listen on port 12000, return messages on port 6448
oscP5 = new OscP5(this, 12000);
dest = new NetAddress(“127.0.0.1”, 6448);
}
// Recieve OSC messages from Wekinator
void oscEvent(OscMessage theOscMessage) {
if (theOscMessage.checkAddrPattern(“/wek/outputs”) == true) {
// Receiving the output from wekinator
float value = theOscMessage.get(0).floatValue();
// Converting the output to int type
output = int(value);
}
}
void draw()
{
// Making the led HIGH or LOW depending on the output from the wekinator
if (output == 1)
{
GPIO.digitalWrite(4, GPIO.HIGH);
}
else if (output == 2)
{
GPIO.digitalWrite(4, GPIO.LOW);
}
}
-
led
+關注
關注
242文章
23767瀏覽量
671758 -
樹莓派
+關注
關注
121文章
1964瀏覽量
107101
發布評論請先 登錄
樹莓派“吉尼斯世界記錄”:將樹莓派的性能發揮到極致的項目!

樹莓派傳感器使用方法 樹莓派 Raspberry Pi 4優缺點
使用樹莓派實現遠程控制的技巧
樹莓派gpio有什么用,樹莓派gpio接口及編程方法
什么是樹莓派?樹莓派是什么架構的
類樹莓派網關:物聯網應用的新標桿

評論