Skip to content

Commit

Permalink
Update README with new example
Browse files Browse the repository at this point in the history
  • Loading branch information
HoldYourWaffle committed Aug 15, 2018
1 parent b683eb2 commit 70ffd89
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,42 @@ dependencies {
## Example
Here's an example that illustrates the basic usage of this api:
```java
import java.awt.Color;
import jimbo.pijava.blinkt.BlinktController;

public class BlinktTest {
public class BlinktExample {

public static void main(String[] args) throws InterruptedException {
BlinktController blinkt = new BlinktController(); //create the controller
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 te controller
blinkt.setBrightness(.1F); //we don't want to blind ourselves

int i = 0;
boolean movingForward = true;
int i = 1;

while (true) {
blinkt.clear(); //clear any previous state
blinkt.set(i, 0, 255, 0); //set LED number 'i' to green
blinkt.push(); //push the new state to the blinkt

i++;
if (i > 7) i = 0;
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(500);
Thread.sleep(250);
}
}

Expand Down

0 comments on commit 70ffd89

Please sign in to comment.