コード例 #1
0
 public void SendString(String writeStr) {
   char[] CharArray = writeStr.toCharArray();
   byte[] WriteData = new byte[CharArray.length];
   for (int i = 0; i < CharArray.length; i++) {
     WriteData[i] = (byte) CharArray[i];
   }
   i2cBus.transaction(WriteData, WriteData.length, null, 0);
 }
コード例 #2
0
  /*
   * reads the arduino and recieves 2 bytes to represent the digital inputs attached to it
   * saves the 2 bytes to 'loByte' and 'hiByte'
   * return: true if and only if it's successful
   */
  public boolean readArduino() {
    byte[] buffer = {0, 0};

    successful =
        !m_I2C.transaction(
            null, 0, buffer,
            2); // doesn't send anything and recieves 2 bytes of data; successful==true if
    // transaction is succesful
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser1, 1, "                     ");
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser2, 1, "                     ");
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser1, 1, "success=" + successful);
    DriverStationLCD.getInstance()
        .println(DriverStationLCD.Line.kUser2, 1, "buffer=" + buffer[1] + ", " + buffer[0]);
    DriverStationLCD.getInstance().updateLCD();
    hiByte = buffer[1];
    loByte = buffer[0];

    return successful;
  }
コード例 #3
0
  /** This function is called periodically during operator control */
  public void teleopPeriodic() {

    // Commented and stuff
    // If it's wrong then uhh
    // My bad fam.

    if (joy.getRawButton(1)) { // Check if the button is pressed
      String WriteString =
          "RGB"; // String that is going to transfer; change to whatever the Arduino code has
      char[] CharArray = WriteString.toCharArray(); // Changes data type (string) to char array
      // Char array: array of chars
      byte[] WriteData =
          new byte
              [CharArray.length]; // Makes the char array able to transfer from roboRio to Arduino
      for (int i = 0; i < CharArray.length; i++) { // Repeats for each char in CharArray
        WriteData[i] = (byte) CharArray[i]; // Sets the char to byte
      }
      Wire.transaction(WriteData, WriteData.length, null, 0); // Finally does transaction
    }

    if (joy.getRawButton(2)) {
      String WriteString = "RGB";
      char[] CharArray = WriteString.toCharArray();
      byte[] WriteData = new byte[CharArray.length];
      for (int i = 0; i < CharArray.length; i++) {
        WriteData[i] = (byte) CharArray[i];
      }
      Wire.transaction(WriteData, WriteData.length, null, 0);
    }
    if (joy.getRawButton(3)) {
      String WriteString = "RGB";
      char[] CharArray = WriteString.toCharArray();
      byte[] WriteData = new byte[CharArray.length];
      for (int i = 0; i < CharArray.length; i++) {
        WriteData[i] = (byte) CharArray[i];
      }
      Wire.transaction(WriteData, WriteData.length, null, 0);
    }
    if (joy.getRawButton(4)) {
      String WriteString = "RGB";
      char[] CharArray = WriteString.toCharArray();
      byte[] WriteData = new byte[CharArray.length];
      for (int i = 0; i < CharArray.length; i++) {
        WriteData[i] = (byte) CharArray[i];
      }
      Wire.transaction(WriteData, WriteData.length, null, 0);
    }

    //    	if (joy.getRawButton(5)) {
    //    		String WriteString = "RGB";
    //    		char[] CharArray = WriteString.toCharArray();
    //    		byte[] WriteData = new byte[CharArray.length];
    //    		for (int i = 0; i < CharArray.length; i++) {
    //    			WriteData[i] = (byte) CharArray[i];
    //    		}
    //    		Wire.transaction(WriteData, WriteData.length, null, 0);
    //    	}
    //    	if (joy.getRawButton(6)) {
    //    		String WriteString = "RGB";
    //    		char[] CharArray = WriteString.toCharArray();
    //    		byte[] WriteData = new byte[CharArray.length];
    //    		for (int i = 0; i < CharArray.length; i++) {
    //    			WriteData[i] = (byte) CharArray[i];
    //    		}
    //    		Wire.transaction(WriteData, WriteData.length, null, 0);
    //    	}
    //    	if (joy.getRawButton(7)) {
    //    		String WriteString = "RGB";
    //    		char[] CharArray = WriteString.toCharArray();
    //    		byte[] WriteData = new byte[CharArray.length];
    //    		for (int i = 0; i < CharArray.length; i++) {
    //    			WriteData[i] = (byte) CharArray[i];
    //    		}
    //    		Wire.transaction(WriteData, WriteData.length, null, 0);
    //    	}
  }