public static void main ( String args [ ] ) throws InterruptedException , IOException { System . out . println ( "<--Pi4J--> Pibrella Example ... started." ) ; // ----------------------------------------------------------------- // create a button listener // ----------------------------------------------------------------- pibrella . button ( ) . addListener ( new ButtonPressedListener ( ) { @ Override public void onButtonPressed ( ButtonEvent event ) { System . out . println ( "[BUTTON PRESSED]" ) ; pulseRate = 30 ; // START or STOP sample tune if ( sampleTuneThread . isAlive ( ) ) stopSampleTune ( ) ; else playSampleTune ( ) ; } } ) ; pibrella . button ( ) . addListener ( new ButtonReleasedListener ( ) { @ Override public void onButtonReleased ( ButtonEvent event ) { System . out . println ( "[BUTTON RELEASED]" ) ; pulseRate = 100 ; } } ) ; // run continuously until user aborts with CTRL-C while ( true ) { // step up the ladder for ( int index = PibrellaLed . RED . getIndex ( ) ; index <= PibrellaLed . GREEN . getIndex ( ) ; index ++ ) { pibrella . getLed ( index ) . pulse ( pulseRate , true ) ; //Thread.sleep(pulseRate); } // step down the ladder for ( int index = PibrellaLed . GREEN . getIndex ( ) ; index >= PibrellaLed . RED . getIndex ( ) ; index -- ) { pibrella . getLed ( index ) . pulse ( pulseRate , true ) ; //Thread.sleep(pulseRate); } } // stop all GPIO activity/threads by shutting down the GPIO controller // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks) //gpio.shutdown(); // <-- uncomment if your program terminates }
Start Pibrella Example