覆盆子pi与ws2801 java

时间:2016-07-06 13:39:45

标签: java led

嘿,我想让ws2801正常工作。只有第一个LED点亮但我无法控制它们

我正在使用带有pi4j库的java。我将raspi的5V引脚连接到LED条纹的5V和地面到raspi地面。 GPIO 19已连接到条带的DOGPIO 23已连接到条带的CI。希望有人能帮助我。

以下是目前的代码:

package test.test2;


import java.util.Random;


import com.pi4j.wiringpi.Gpio;
import com.pi4j.wiringpi.Spi;

public class App {
    public static void main(String[] args) {

        System.out.println("Test 2!");

        System.out.println("Out:" + Spi.wiringPiSPISetup(0, 500000));// 1mhz=1000000
        System.out.println("Out:" + Gpio.wiringPiSetupSys());
        int num_leds = 110;
        try {
            // Using a file vs wiringPi:
            //
            // FileOutputStream fos = new FileOutputStream(new
            // File("/dev/spidev0.0"));
            // fos.write(colors);
            // fos.flush(); //limited success with this

            Random randomGenerator = new Random();
            for (;;) {
                int colorToUse1 = randomGenerator.nextInt(255);
                int colorToUse2 = randomGenerator.nextInt(255);
                int colorToUse3 = randomGenerator.nextInt(255);
                long startTimeMillis = System.currentTimeMillis();

                // fade all lights out...

                for (int j = 0; j < 255; j++) {
                    byte[] colors = new byte[num_leds * 3];
                    for (int i = 0; i < num_leds * 3; i = i + 3) {
                        colors[i] = (byte) colorToUse1;
                        colors[i + 1] = (byte) colorToUse2;
                        colors[i + 2] = (byte) colorToUse3;
                    }
                    if (colorToUse1 != 0)
                        colorToUse1--;
                    if (colorToUse2 != 0)
                        colorToUse2--;
                    if (colorToUse3 != 0)
                        colorToUse3--;
                    Spi.wiringPiSPIDataRW(0, colors, colors.length);
                    Gpio.delayMicroseconds(800); // need to determine optimal value
                }
                System.out.println("Elapsed:" + (System.currentTimeMillis() - startTimeMillis));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

更新:它正在运作。遇到了错误的事情。非常感谢

0 个答案:

没有答案