1

I'm trying to program a kind of dmx controller, therefore I got a RaspberryPi and now I want to write a program to controlle a GPIO with pi4j. The idea is to ask for the GPIO that should be the output, save it in a int and reuse this to tell pi4j which GPIO I would like to be the Output.

Sorry for the bad code :)

I'm a native Germanspeaker so the println are in German.

System.out.println("GPIO des DMX Outputs :");

BufferedReader br_dmx_out = new BufferedReader(new InputStreamReader(System.in));

int dmx_out = Integer.parseInt(br_dmx_out.readLine());

System.out.println("Der DMX Output GPIO ist also GPIO " + dmx_out);         

// GPIO Controll

String predef = ""+dmx_out;
/*
String def = MessageFormat.format("RaspiPin.GPIO_0{0}",predef);
System.out.println(def);
*/
Pin pin_dmx = "RaspiPin.GPIO_0"+ predef;

GpioController gpio = GpioFactory.getInstance();

GpioPinDigitalOutput dmx_output = gpio.provisionDigitalOutputPin(pin_dmx);

Normaly you code:

GpioPinDigitalOutput dmx_output = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);

Java says:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Type mismatch: cannot convert from String to Pin

    at test.main(test.java:44)

I also tried a switch/case but this wouldn't either

GpioController gpio = GpioFactory.getInstance();

switch(dmx_out)
{
case 2:
    GpioPinDigitalOutput dmx_output = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02);
    break;

Java's error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    Duplicate local variable dmx_output
    dmx_output cannot be resolved
    dmx_output cannot be resolved

    at test.main(test.java:59)
Bulat
  • 720
  • 7
  • 15
Ramadorrn
  • 21
  • 1
  • 4

1 Answers1

0

You are trying to assign a String to the Pin interface.

https://pi4j.com/1.2/apidocs/com/pi4j/io/gpio/Pin.html

To get an implementation of it you might want to call the constructor of PinImpl as in the following example:

https://github.com/Pi4J/pi4j/blob/master/pi4j-gpio-extension/src/main/java/com/pi4j/gpio/extension/mcp/MCP3204Pin.java

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186