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)