Shop OBEX P1 Docs P2 Docs Learn Events
Help with code: Conditional Operator "AND" — Parallax Forums

Help with code: Conditional Operator "AND"

TonyATonyA Posts: 226
edited 2006-03-04 22:10 in BASIC Stamp
I'm working on some code that goes like this:

RctimeVal = Reading from a force sensitive resistor

IF RCtimeVal = x
"and then"
RctimeVal = y THEN
Do This
Else
Do Nothing

Could the "AND" operator be used in place of my "and then" in the code above?

Thanks for any help.

Tony A

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-03 13:15
    RCtimeValX CON 420
    RctimeValY CON 450
    someval    CON 300
    thisval    CON 500
    thatval    CON 1000
     
    Main:
      IF (RCtimevalX = someval) AND (RCtimevalY = someval) THEN scram1
      IF (RCtimevalX > thisval) AND (RCtimevalY < thatval) THEN scram2
      GOTO main
     
    scram1:
      end
    
    scram2:
      end
    
  • TonyATonyA Posts: 226
    edited 2006-03-03 13:32
    My application is to use an FSR (force sensor), where if you touch it once only one event will occur (SEROUT [noparse][[/noparse]Midi note]), one midi note per touch. It will only produce another midi note if you touch it a second time.

    I was wondering if something like this would work:

    RCtimevalx Var BYTE
    RCtimevaly Var BYTE

    Main:
    RCtime result = RCtimeValx 'reading from the FSR

    RCtimevaly = ? 'don't know what to do here, or if this would work

    IF (RCtimevalx = 0) AND (RCtimevaly > 0) THEN MidiOut
    ELSE
    SEROUT [noparse][[/noparse]Note off]

    MidiOut:
    SEROUT [noparse][[/noparse]Note on]
    GOTO Main

    Post Edited (TonyA) : 3/3/2006 2:21:06 PM GMT
  • kelvin jameskelvin james Posts: 531
    edited 2006-03-04 06:59
    I am not exactly sure what you are trying to do here, is it you want to set a note on / note off time duration? What is happening with your program now? If you are getting repeats, the timing of the program cycle may be faster than the cycle of the sensor . You could try a delay in the program loop, and reset the rc variable back to zero before the next loop. There are some other options, but need more info.

    kelvin
  • TonyATonyA Posts: 226
    edited 2006-03-04 22:10
    I have been thinking up a way to get one event (serout) per tap, using a tactile sensor. Basically I want to make a midi drum. So, I need to detect the state of a switch going from low to high. With the help of people here and from the book "Physical Computing" I came up with a modified version of the "edge detection" code. I'll post my results. Thanks.

    Tony A
Sign In or Register to comment.