Shop OBEX P1 Docs P2 Docs Learn Events
BS1USB to Java — Parallax Forums

BS1USB to Java

Edje09Edje09 Posts: 2
edited 2011-09-27 21:53 in BASIC Stamp
I recently started using my BS1USB and I had a question about using output with other programming languages. I've attached a hall effect sensor and wrote the code below. Basically, the code loops every 10 units of time and checks the state of the sensor. If the sensor is "off" (no magnet within range), debug returns 0. If the sensor is "on" (magnet within range), it returns 1.
Main:
IF PORT => 0 THEN Win
'GOSUB Main
Win:
DEBUG CLS
DEBUG PORT
PAUSE 10
GOSUB Main

What I'm trying to do, in part, is build a bike computer. I'd like to write a program in another language (probably Java, since that's really all I'm comfortable coding with at the moment) that monitors the debug output from the BS1USB and performs calculations based on the frequency of outputs to determine how fast the wheel (with attached magnet) is spinning. I also want to use that information to drive a video.

I realize the above code is not very elegant, and it has a pretty low fidelity since it's dependent on the time set for loop. If anyone has a more elegant solution (like an event listener to determine precisely when an output is sent), I'd love to hear it, but my primary question is regarding the output to other languages.

Thanks in advance!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-25 19:23
    1) Be careful about using GOSUB as a GOTO. They're not interchangeable. Each GOSUB has to have a RETURN.

    2) The DEBUG output is complex. The Nuts and Volts Column #20 discusses the DEBUG data format. You should be able to write a Java program to extract what you need.
  • bsnutbsnut Posts: 521
    edited 2011-09-27 21:53
    I am going to expand on Mike's point a little bit. For what you are doing, your Basic Stamp 1 code needs to look like what I done below.
    Main:
    IF PORT => 0 THEN Win
    GOTO Main
    Win:
    DEBUG CLS
    DEBUG PORT
    PAUSE 10
    GOTO Main
Sign In or Register to comment.