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
0 parents
commit d540374
Showing
5 changed files
with
191 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,3 @@ | ||
*.iml | ||
*~ | ||
target |
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,8 @@ | ||
Raspberry Pi + some electronic parts + Java + Pi4J | ||
|
||
see http://www.youtube.com/watch?v=Ydytk35zhPs | ||
|
||
Links: | ||
http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/ | ||
http://jdk8.java.net/fxarmpreview/index.html | ||
http://pi4j.com/index.html |
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,83 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>net.slintes.raspi</groupId> | ||
<artifactId>Ampel</artifactId> | ||
<version>0.1</version> | ||
|
||
<properties> | ||
<pi4jVersion>0.0.5-SNAPSHOT</pi4jVersion> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.pi4j</groupId> | ||
<artifactId>pi4j-core</artifactId> | ||
<version>${pi4jVersion}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>net.slintes.raspi.Ampel</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptor>src/main/assembly/assembly.xml</descriptor> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.7</version> | ||
<configuration> | ||
<uniqueVersion>false</uniqueVersion> | ||
<generatePom>false</generatePom> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
<extensions> | ||
<extension> | ||
<groupId>org.apache.maven.wagon</groupId> | ||
<artifactId>wagon-ssh</artifactId> | ||
<version>2.3</version> | ||
</extension> | ||
</extensions> | ||
</build> | ||
|
||
<distributionManagement> | ||
<repository> | ||
<id>raspi</id> | ||
<url>scp://pi:xxxx@raspberrypi.local/home/pi/ampel</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
<repositories> | ||
<repository> | ||
<id>oss-snapshots-repo</id> | ||
<name>Sonatype OSS Maven Repository</name> | ||
<url>https://oss.sonatype.org/content/groups/public</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
<updatePolicy>always</updatePolicy> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
</project> |
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,23 @@ | ||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> | ||
|
||
<id>assembly-with-dll</id> | ||
<formats> | ||
<format>jar</format> | ||
</formats> | ||
<includeBaseDirectory>false</includeBaseDirectory> | ||
<dependencySets> | ||
<!-- package the regular dependencies --> | ||
<dependencySet> | ||
<outputDirectory>/</outputDirectory> | ||
<useProjectArtifact>true</useProjectArtifact> | ||
<unpack>true</unpack> | ||
<scope>runtime</scope> | ||
<!-- exclude so --> | ||
<excludes> | ||
<exclude>com.pi4j:pi4j-native:so:hard-float:${pi4jVersion}</exclude> | ||
<exclude>com.pi4j:pi4j-native:so:soft-float:${pi4jVersion}</exclude> | ||
</excludes> | ||
</dependencySet> | ||
</dependencySets> | ||
</assembly> |
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,74 @@ | ||
package net.slintes.raspi; | ||
|
||
import com.pi4j.io.gpio.*; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: slintes | ||
* Date: 26.12.12 | ||
* Time: 16:09 | ||
*/ | ||
public class Ampel { | ||
|
||
private static final Pin PIN_RED = RaspiPin.GPIO_04; // orig 24 | ||
private static final Pin PIN_YELLOW = RaspiPin.GPIO_05; // orig 25 | ||
private static final Pin PIN_GREEN = RaspiPin.GPIO_06; // orig 26 | ||
private static final String NAME_RED = "red"; | ||
private static final String NAME_YELLOW = "yellow"; | ||
private static final String NAME_GREEN = "green"; | ||
private static final int STATE_RED = 1; | ||
private static final int STATE_YELLOW = 2; | ||
private static final int STATE_GREEN = 4; | ||
|
||
public static void main(String[] args){ | ||
Ampel ampel = new Ampel(); | ||
ampel.start(); | ||
} | ||
|
||
private void start() { | ||
GpioController gpio = GpioFactory.getInstance(); | ||
GpioPinDigitalOutput redLED = gpio.provisionDigitalOutputPin(PIN_RED, NAME_RED, PinState.LOW); | ||
GpioPinDigitalOutput yellowLED = gpio.provisionDigitalOutputPin(PIN_YELLOW, NAME_YELLOW, PinState.LOW); | ||
GpioPinDigitalOutput greenLED = gpio.provisionDigitalOutputPin(PIN_GREEN, NAME_GREEN, PinState.LOW); | ||
|
||
redLED.setShutdownOptions(true, PinState.LOW); | ||
yellowLED.setShutdownOptions(true, PinState.LOW); | ||
greenLED.setShutdownOptions(true, PinState.LOW); | ||
|
||
int durationLong = 2000; | ||
int durationShort= 800; | ||
|
||
StateAndDuration[] stateAndDurations = {new StateAndDuration(STATE_RED, durationLong), | ||
new StateAndDuration(STATE_RED + STATE_YELLOW, durationShort), | ||
new StateAndDuration(STATE_GREEN, durationLong), | ||
new StateAndDuration(STATE_YELLOW, durationLong)}; | ||
|
||
while(true){ | ||
for (int i=0, length=stateAndDurations.length; i<length; i++){ | ||
|
||
StateAndDuration stateAndDuration = stateAndDurations[i]; | ||
|
||
redLED.setState((stateAndDuration.state & STATE_RED) == STATE_RED); | ||
yellowLED.setState((stateAndDuration.state & STATE_YELLOW) == STATE_YELLOW); | ||
greenLED.setState((stateAndDuration.state & STATE_GREEN) == STATE_GREEN); | ||
|
||
try { | ||
Thread.sleep(stateAndDuration.duration); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
class StateAndDuration { | ||
|
||
int state; | ||
int duration; | ||
|
||
StateAndDuration(int state, int duration) { | ||
this.state = state; | ||
this.duration = duration; | ||
} | ||
} | ||
} |