Jump to content

tinytinkerer

Members
  • Gesamte Inhalte

    2
  • Benutzer seit

  • Letzter Besuch

Alle erstellten Inhalte von tinytinkerer

  1. Hallo zusammen, ich soll Sensordaten vom RED-Brick persistieren. Kann mir da wer weiterhelfen? Ich stehe gerade voll auf dem Schlauch.//Edit hat sich erledigt: package com.company; import com.tinkerforge.IPConnection; import com.tinkerforge.BrickletAccelerometer; import java.io.*; public class Main { private static final String HOST = "localhost"; private static final int PORT = 4223; // Change XYZ to the UID of your Accelerometer Bricklet private static final String UID = "Cge"; // Note: To make the example code cleaner we do not handle exceptions. Exceptions // you might normally want to catch are described in the documentation public static void main(String args[]) throws Exception { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletAccelerometer a = new BrickletAccelerometer(UID, ipcon); // Create device object ipcon.connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Add acceleration listener a.addAccelerationListener(new BrickletAccelerometer.AccelerationListener() { public void acceleration(short x, short y, short z) { PrintWriter outputfile = null; try { outputfile = new PrintWriter((new BufferedWriter(new FileWriter("Beschleunigung.txt",true)))); //replace your System.out.print("your output"); outputfile.println(+x/1000.0+";"+y/1000.0+";"+z/1000.0+";"); outputfile.println(""); }catch (IOException ioe) { ioe.printStackTrace(); }finally { if (outputfile != null){ outputfile.flush(); outputfile.close(); } } } }); // Set period for acceleration callback to 1s (1000ms) // Note: The acceleration callback is only called every second // if the acceleration has changed since the last call! a.setAccelerationCallbackPeriod(1000); System.out.println("Press key to exit"); System.in.read(); ipcon.disconnect(); } }
×
×
  • Neu erstellen...