forked from hackerjimbo/PiJava
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be55b39
commit 6f0a988
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import jimbo.pijava.blinkt.BlinktController; | ||
import java.awt.Color; | ||
|
||
public class BlinktExample { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
System.out.println("Starting demo"); //the VM can take some time to load on the pi so we print a nice little heads up that we're starting | ||
|
||
BlinktController blinkt = new BlinktController(); //create the controller | ||
blinkt.setBrightness(.1F); //we don't want to blind ourselves | ||
|
||
boolean movingForward = true; | ||
int i = 1; | ||
|
||
while (true) { | ||
blinkt.clear(); //clear any previous state | ||
|
||
blinkt.set(i-1, Color.RED); //set the left pixel to red | ||
blinkt.set(i, 0, 255, 0); //set the middle pixel to green | ||
blinkt.set(i+1, Color.BLUE, 1); //set the last pixel to blue with full brightness | ||
|
||
blinkt.push(); //push state to the GPIO pins | ||
|
||
//Some back and forth controlling | ||
if (movingForward) i++; | ||
else i--; | ||
|
||
if (i >= 7) { | ||
i = 5; | ||
movingForward = false; | ||
} else if (i <= 0) { | ||
i = 2; | ||
movingForward = true; | ||
} | ||
|
||
Thread.sleep(250); | ||
} | ||
} | ||
|
||
} |