From 4ae4b314c5f3f9ddb2c409b90a8957e225ca6b41 Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Wed, 14 Jun 2017 18:04:37 -0500 Subject: [PATCH] Adds initial files --- .gitignore | 9 + .idea/compiler.xml | 9 + .idea/gradle.xml | 17 + .../Gradle__com_google_guava_guava_21_0.xml | 11 + .../libraries/Gradle__io_mraa_mraa_1_5_1.xml | 11 + .idea/libraries/Gradle__junit_junit_4_12.xml | 11 + ...org_apache_commons_commons_math3_3_6_1.xml | 11 + ...Gradle__org_hamcrest_hamcrest_core_1_3.xml | 11 + .idea/misc.xml | 4 + .idea/modules.xml | 10 + .idea/modules/IOBoard.iml | 12 + .idea/modules/IOBoard_main.iml | 16 + .idea/modules/IOBoard_test.iml | 20 + .idea/vcs.xml | 6 + .idea/workspace.xml | 888 ++++++++++++++++++ boardtest.py | 138 +++ build.gradle | 31 + settings.gradle | 18 + src/main/java/com/henrypump/io/AnalogIn.java | 108 +++ src/main/java/com/henrypump/io/DigitalIn.java | 75 ++ .../java/com/henrypump/io/DigitalOut.java | 85 ++ src/main/java/com/henrypump/io/MuxSetup.java | 92 ++ 22 files changed, 1593 insertions(+) create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/libraries/Gradle__com_google_guava_guava_21_0.xml create mode 100644 .idea/libraries/Gradle__io_mraa_mraa_1_5_1.xml create mode 100644 .idea/libraries/Gradle__junit_junit_4_12.xml create mode 100644 .idea/libraries/Gradle__org_apache_commons_commons_math3_3_6_1.xml create mode 100644 .idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/modules/IOBoard.iml create mode 100644 .idea/modules/IOBoard_main.iml create mode 100644 .idea/modules/IOBoard_test.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 boardtest.py create mode 100644 build.gradle create mode 100644 settings.gradle create mode 100644 src/main/java/com/henrypump/io/AnalogIn.java create mode 100644 src/main/java/com/henrypump/io/DigitalIn.java create mode 100644 src/main/java/com/henrypump/io/DigitalOut.java create mode 100644 src/main/java/com/henrypump/io/MuxSetup.java diff --git a/.gitignore b/.gitignore index 6143e53..d2290d9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,12 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +.gradle/* +build/* + +gradlew + +gradle/wrapper/gradle-wrapper.properties + +gradlew.bat diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..50e8a9f --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..a5c3ae1 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_google_guava_guava_21_0.xml b/.idea/libraries/Gradle__com_google_guava_guava_21_0.xml new file mode 100644 index 0000000..32b92b3 --- /dev/null +++ b/.idea/libraries/Gradle__com_google_guava_guava_21_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__io_mraa_mraa_1_5_1.xml b/.idea/libraries/Gradle__io_mraa_mraa_1_5_1.xml new file mode 100644 index 0000000..96841ac --- /dev/null +++ b/.idea/libraries/Gradle__io_mraa_mraa_1_5_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__junit_junit_4_12.xml b/.idea/libraries/Gradle__junit_junit_4_12.xml new file mode 100644 index 0000000..04c10dd --- /dev/null +++ b/.idea/libraries/Gradle__junit_junit_4_12.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_apache_commons_commons_math3_3_6_1.xml b/.idea/libraries/Gradle__org_apache_commons_commons_math3_3_6_1.xml new file mode 100644 index 0000000..ef0bbf5 --- /dev/null +++ b/.idea/libraries/Gradle__org_apache_commons_commons_math3_3_6_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..8262f72 --- /dev/null +++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..99ae653 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b96ffd6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/IOBoard.iml b/.idea/modules/IOBoard.iml new file mode 100644 index 0000000..7313704 --- /dev/null +++ b/.idea/modules/IOBoard.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/IOBoard_main.iml b/.idea/modules/IOBoard_main.iml new file mode 100644 index 0000000..5f5ce54 --- /dev/null +++ b/.idea/modules/IOBoard_main.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/IOBoard_test.iml b/.idea/modules/IOBoard_test.iml new file mode 100644 index 0000000..2d8f4af --- /dev/null +++ b/.idea/modules/IOBoard_test.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..71852c4 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,888 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DigitalIn + readDigital + + + AnalogIn + readAnalog + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1497454922456 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/boardtest.py b/boardtest.py new file mode 100644 index 0000000..607716a --- /dev/null +++ b/boardtest.py @@ -0,0 +1,138 @@ +"""Test the IO Board.""" + +import mraa +import time + +relay = [] + +for x in range(0, 6): + pin = mraa.Gpio(x) + pin.dir(mraa.DIR_OUT) + relay.append(pin) + pin.write(0) + +pinRedLED = mraa.Gpio(8) +pinRedLED.dir(mraa.DIR_OUT) + +pinGreenLED = mraa.Gpio(9) +pinGreenLED.dir(mraa.DIR_OUT) + +input_mux = [ + [], + [0, 0, 0], # Input 1 + [1, 0, 0], # Input 2 + [0, 1, 0], # Input 3 + [1, 1, 0], # Input 4 + [0, 0, 1], # Input 5 + [1, 0, 1], # Input 6 + [0, 1, 1], # Input 7 + [1, 1, 1], # Input 8 +] + +pinA0 = mraa.Gpio(14) +pinA0.dir(mraa.DIR_OUT) +pinA1 = mraa.Gpio(15) +pinA1.dir(mraa.DIR_OUT) +pinA2 = mraa.Gpio(16) +pinA2.dir(mraa.DIR_OUT) +pinA3 = mraa.Gpio(17) +pinA3.dir(mraa.DIR_IN) + +spi_bus = mraa.Spi(0) +print(spi_bus.lsbmode(False)) + + +def red_LED(out): + """Set the Red LED to the specified output.""" + if out: + pinRedLED.write(1) + else: + pinRedLED.write(0) + + +def green_LED(out): + """Set the Green LED to the specified output.""" + if out: + pinGreenLED.write(1) + else: + pinGreenLED.write(0) + + +def relay_loop(): + """Loop through all relays.""" + loops = 0 + while loops < 10: + for p in relay: + p.write(1) + time.sleep(1) + p.write(0) + loops += 1 + + +def read_dig_in(io_port): + """Read IO Board digital input.""" + if io_port == 0 or io_port > 8: + print("CANNOT READ A PORT THAT DOES NOT EXIST: {}".format(io_port)) + return False + pin_values = input_mux[io_port] + pinA0.write(pin_values[0]) + pinA1.write(pin_values[1]) + pinA2.write(pin_values[2]) + return pinA3.read() == 0 + + +def dig_in_loop(): + """Read all digital inputs.""" + for i in range(1, 9): + print("DIGIN {} = {}".format(i, read_dig_in(i))) + + +def led_flash(loops): + """Flash the LED's from red to green.""" + led_loops = 0 + while led_loops < loops: + red_LED(True) + green_LED(False) + time.sleep(0.25) + red_LED(False) + green_LED(True) + time.sleep(0.25) + led_loops += 1 + + red_LED(False) + green_LED(False) + + +def read_analog_in(io_port): + """Read IO Board digital input.""" + global spi_bus + if io_port < 1 or io_port > 4: + print("CANNOT READ A PORT THAT DOES NOT EXIST: {}".format(io_port)) + return False + pin_values = input_mux[io_port] + pinA0.write(pin_values[0]) + pinA1.write(pin_values[1]) + pinA2.write(pin_values[2]) + ok_status = False + + while ok_status is False: + pinA0.write(pin_values[0]) + pinA1.write(pin_values[1]) + pinA2.write(pin_values[2]) + x = spi_bus.write(bytearray([0, 0, 0])) + print((x[0], x[1], x[2])) + c_bin = format(x[2], '#010b')[2:] + + if c_bin[-3:] == "101": + ok_status = True + print("OK: {}, Status: {}".format(ok_status, c_bin)) + print(x[0] * 256 + x[1]) + time.sleep(10) + + + +if __name__ == '__main__': + # led_flash(10) + + print("Analog {}".format(1)) + read_analog_in(1) diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..124abeb --- /dev/null +++ b/build.gradle @@ -0,0 +1,31 @@ +/* + * This build file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java Library project to get you started. + * For more details take a look at the Java Libraries chapter in the Gradle + * user guide available at https://docs.gradle.org/3.5/userguide/java_library_plugin.html + */ + +// Apply the java-library plugin to add support for Java Library +apply plugin: 'java-library' + +// In this section you declare where to find the dependencies of your project +repositories { + // Use jcenter for resolving your dependencies. + // You can declare any Maven/Ivy/file repository here. + jcenter() +} + +dependencies { + // This dependency is exported to consumers, that is to say found on their compile classpath. + api 'org.apache.commons:commons-math3:3.6.1' + + // This dependency is used internally, and not exposed to consumers on their own compile classpath. + implementation 'com.google.guava:guava:21.0' + + // Use JUnit test framework + testImplementation 'junit:junit:4.12' + + compile group: 'io.mraa', name: 'mraa', version:'1.5.1' +} + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..4436d31 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,18 @@ +/* + * This settings file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * In a single project build this file can be empty or even removed. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user guide at https://docs.gradle.org/3.5/userguide/multi_project_builds.html + */ + +/* +// To declare projects as part of a multi-project build use the 'include' method +include 'shared' +include 'api' +include 'services:webservice' +*/ + +rootProject.name = 'IOBoard' diff --git a/src/main/java/com/henrypump/io/AnalogIn.java b/src/main/java/com/henrypump/io/AnalogIn.java new file mode 100644 index 0000000..830f944 --- /dev/null +++ b/src/main/java/com/henrypump/io/AnalogIn.java @@ -0,0 +1,108 @@ +package com.henrypump.io; + +import java.util.List; + +/** + * Created by patrickjmcd on 6/14/17. + */ +public class AnalogIn { + + public int channel; + public int rawValue; + public double lastValue; + public double rawMax, rawMin, euMax, euMin; + public List channelMux; + private double[] history = new double[100]; + + AnalogIn(int channel, double rawMin, double rawMax, double euMin, double euMax) { + this.channel = channel; + this.channelMux = MuxSetup.muxValues.get(channel); + this.rawMax = rawMax; + this.rawMin = rawMin; + this.euMax = euMax; + this.euMin = euMin; + } + + double getHistory(int pointIndex) { + return history[pointIndex]; + } + + double setValue(int value) { + this.rawValue = value; + double pv = ((euMax - euMin)/(rawMax - rawMin)) * rawValue + (euMax - ((euMax - euMin)/(rawMax - rawMin)) * rawMax); + lastValue = pv; + System.arraycopy(history, 0, history,1, history.length - 1); + history[0] = lastValue; + return pv; + } + + public static void main(String[] args) { + MuxSetup mux = new MuxSetup(); + System.out.println("Testing Analog Inputs"); + int rawIn; + + + AnalogIn aI1 = new AnalogIn(1, 0, 65535, 0, 10); + AnalogIn aI2 = new AnalogIn(2, 0, 65535, 0, 10); + AnalogIn aI3 = new AnalogIn(3, 0, 65535, 0, 10); + AnalogIn aI4 = new AnalogIn(4, 0, 65535, 0, 10); + + for (int i = 0; i < 100; i++) { + mux.set(aI1.channelMux.get(0), aI1.channelMux.get(1), aI1.channelMux.get(2)); + rawIn = mux.readAnalog(); + if (rawIn != -1) { + aI1.setValue(mux.readAnalog()); + System.out.println("Input " + aI1.channel + ": " + aI1.lastValue); + } else { + try { + Thread.sleep(25); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + mux.set(aI2.channelMux.get(0), aI2.channelMux.get(1), aI2.channelMux.get(2)); + + rawIn = mux.readAnalog(); + if (rawIn != -1) { + aI2.setValue(mux.readAnalog()); + System.out.println("Input " + aI2.channel + ": " + aI2.lastValue); + } else { + try { + Thread.sleep(25); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + mux.set(aI3.channelMux.get(0), aI3.channelMux.get(1), aI3.channelMux.get(2)); + rawIn = mux.readAnalog(); + if (rawIn != -1) { + aI3.setValue(mux.readAnalog()); + System.out.println("Input " + aI3.channel + ": " + aI3.lastValue); + } else { + try { + Thread.sleep(25); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + mux.set(aI4.channelMux.get(0), aI4.channelMux.get(1), aI4.channelMux.get(2)); + rawIn = mux.readAnalog(); + if (rawIn != -1) { + aI4.setValue(mux.readAnalog()); + System.out.println("Input " + aI4.channel + ": " + aI4.lastValue); + } else { + try { + Thread.sleep(25); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } + + + } +} diff --git a/src/main/java/com/henrypump/io/DigitalIn.java b/src/main/java/com/henrypump/io/DigitalIn.java new file mode 100644 index 0000000..71356a2 --- /dev/null +++ b/src/main/java/com/henrypump/io/DigitalIn.java @@ -0,0 +1,75 @@ +package com.henrypump.io; + +import mraa.Dir; +import mraa.Gpio; +import mraa.Result; + +import java.util.List; + +/** + * Created by patrickjmcd on 6/14/17. + */ + +public class DigitalIn { + public int channel; + public int value; + public List channelMux; + DigitalIn(int channel){ + this.channel = channel; + this.channelMux = MuxSetup.muxValues.get(channel); + } + + void setValue(int value){ + this.value = value; + } + + public static void main(String[] args){ + MuxSetup mux = new MuxSetup(); + System.out.println("Testing Digital Inputs"); + + + DigitalIn dI1 = new DigitalIn(1); + DigitalIn dI2 = new DigitalIn(2); + DigitalIn dI3 = new DigitalIn(3); + DigitalIn dI4 = new DigitalIn(4); + DigitalIn dI5 = new DigitalIn(5); + DigitalIn dI6 = new DigitalIn(6); + DigitalIn dI7 = new DigitalIn(7); + DigitalIn dI8 = new DigitalIn(8); + + mux.set(dI1.channelMux.get(0), dI1.channelMux.get(1), dI1.channelMux.get(2)); + dI1.setValue(mux.readDigital()); + System.out.println("Input " + dI1.channel + ": " + dI1.value); + + mux.set(dI2.channelMux.get(0), dI2.channelMux.get(1), dI2.channelMux.get(2)); + dI2.setValue(mux.readDigital()); + System.out.println("Input " + dI2.channel + ": " + dI2.value); + + mux.set(dI3.channelMux.get(0), dI3.channelMux.get(1), dI3.channelMux.get(2)); + dI3.setValue(mux.readDigital()); + System.out.println("Input " + dI3.channel + ": " + dI3.value); + + mux.set(dI4.channelMux.get(0), dI4.channelMux.get(1), dI4.channelMux.get(2)); + dI4.setValue(mux.readDigital()); + System.out.println("Input " + dI4.channel + ": " + dI4.value); + + mux.set(dI5.channelMux.get(0), dI5.channelMux.get(1), dI5.channelMux.get(2)); + dI5.setValue(mux.readDigital()); + System.out.println("Input " + dI5.channel + ": " + dI5.value); + + mux.set(dI6.channelMux.get(0), dI6.channelMux.get(1), dI6.channelMux.get(2)); + dI6.setValue(mux.readDigital()); + System.out.println("Input " + dI6.channel + ": " + dI6.value); + + mux.set(dI7.channelMux.get(0), dI7.channelMux.get(1), dI7.channelMux.get(2)); + dI7.setValue(mux.readDigital()); + System.out.println("Input " + dI7.channel + ": " + dI7.value); + + mux.set(dI8.channelMux.get(0), dI8.channelMux.get(1), dI8.channelMux.get(2)); + dI8.setValue(mux.readDigital()); + System.out.println("Input " + dI8.channel + ": " + dI8.value); + + + + } +} diff --git a/src/main/java/com/henrypump/io/DigitalOut.java b/src/main/java/com/henrypump/io/DigitalOut.java new file mode 100644 index 0000000..0d80928 --- /dev/null +++ b/src/main/java/com/henrypump/io/DigitalOut.java @@ -0,0 +1,85 @@ +package com.henrypump.io; + +import mraa.Dir; +import mraa.Gpio; +import mraa.Result; + +/** + * Created by patrickjmcd on 6/14/17. + */ +public class DigitalOut { + int channel; + Gpio gpioPin; + + DigitalOut(int channel){ + if ((channel >=0 && channel <=5) || (channel == 8) || (channel == 9)) { + this.channel = channel; + gpioPin = new Gpio(channel); + gpioPin.dir(Dir.DIR_OUT); + } else { + System.err.println("Error: This channel does not exist,."); + System.exit(Result.ERROR_INVALID_PARAMETER.swigValue()); + } + + } + + void write(int value){ + gpioPin.write(value); + } + + public static void main(String[] args){ + DigitalOut dO0 = new DigitalOut(0); + DigitalOut dO1 = new DigitalOut(1); + DigitalOut dO2 = new DigitalOut(2); + DigitalOut dO3 = new DigitalOut(3); + DigitalOut dO4 = new DigitalOut(4); + DigitalOut dO5 = new DigitalOut(5); + DigitalOut redLED = new DigitalOut(8); + DigitalOut greenLED = new DigitalOut(9); + System.out.println("Testing Digital Outputs"); + + + try { + dO0.write(1); + Thread.sleep(500); + dO1.write(1); + Thread.sleep(500); + dO2.write(1); + Thread.sleep(500); + dO3.write(1); + Thread.sleep(500); + dO4.write(1); + Thread.sleep(500); + dO5.write(1); + Thread.sleep(500); + dO5.write(0); + Thread.sleep(500); + dO4.write(0); + Thread.sleep(500); + dO3.write(0); + Thread.sleep(500); + dO2.write(0); + Thread.sleep(500); + dO1.write(0); + Thread.sleep(500); + dO0.write(0); + Thread.sleep(500); + + System.out.println("Testing the status LEDs"); + for (int i = 0; i < 10; i++) { + redLED.write(0); + greenLED.write(1); + Thread.sleep(250); + redLED.write(1); + greenLED.write(0); + Thread.sleep(250); + + } + redLED.write(0); + greenLED.write(0); + + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/henrypump/io/MuxSetup.java b/src/main/java/com/henrypump/io/MuxSetup.java new file mode 100644 index 0000000..8ebb986 --- /dev/null +++ b/src/main/java/com/henrypump/io/MuxSetup.java @@ -0,0 +1,92 @@ +package com.henrypump.io; + +import mraa.Dir; +import mraa.Gpio; +import mraa.Spi; + +import java.util.Arrays; +import java.util.List; + +/** + * Created by patrickjmcd on 6/14/17. + */ +public class MuxSetup { + + private int A0val = 0; + private int A1val = 0; + private int A2val = 0; + + private Gpio gpioA0; + private Gpio gpioA1; + private Gpio gpioA2; + private Gpio gpioA3; + private Spi spi; + + public static List> muxValues = Arrays.asList( + Arrays.asList(), + Arrays.asList(0,0,0), + Arrays.asList(1,0,0), + Arrays.asList(0,1,0), + Arrays.asList(1,1,0), + Arrays.asList(0,0,1), + Arrays.asList(1,0,1), + Arrays.asList(0,1,1), + Arrays.asList(1,1,1) + ); + + MuxSetup(){ + gpioA0 = new Gpio(14); + gpioA0.dir(Dir.DIR_OUT); + + gpioA1 = new Gpio(15); + gpioA1.dir(Dir.DIR_OUT); + + gpioA2 = new Gpio(16); + gpioA2.dir(Dir.DIR_OUT); + + gpioA3 = new Gpio(17); + gpioA3.dir(Dir.DIR_IN); + + spi = new Spi(0); + } + + public int set(int a0val, int a1val, int a2val){ + this.A0val = a0val; + this.A1val = a1val; + this.A2val = a2val; + return apply(); + } + + public int apply(){ + gpioA0.write(A0val); + gpioA1.write(A1val); + gpioA2.write(A2val); + + return A0val + A1val * 2 + A2val * 4; + } + + public int readDigital(){ + if (gpioA3.read() == 0){ + return 1; + } else { + return 0; + } + } + + public int readAnalog() { + int a = spi.writeByte((short) 0); + int b = spi.writeByte((short) 0); + int c = spi.writeByte((short) 0); + +// System.out.println("a= " + a + ", b= " + b + ", c= " + c); +// System.out.println("Raw= " + (a * 256 + b)); + + if (c == 13){ + int x = a * 256; + x = x + b; + return x; + } else { + return -1; + } + }; +}