Shop OBEX P1 Docs P2 Docs Learn Events
Code — Parallax Forums

Code

debonenedebonene Posts: 19
edited 2009-11-20 21:32 in BASIC Stamp
Hi my program is not completely executing my exact instruction set. I want it to check two sensors and if the difference of the two sensors is greater than a certain constant assigned then make the move instructed. My code attached only compares the sensor and whenever there is a slight difference it execute. :

Comments

  • JDJD Posts: 570
    edited 2009-11-20 21:25
    Debonene,

    It looks like the values you are shifting to the ADC have been changed from the original program; which is what sets the mode and channel you are reading in. For example, if you are want to read Channel 0 in a single ended mode, you could use the following:

    · LOW CS
    · SHIFTOUT DataIn, Clock, MSBFIRST, [noparse][[/noparse]%11000\5 ]···· ' Select CH0, Single-Ended
    · SHIFTIN DataOut, Clock, MSBPOST, [noparse][[/noparse]result0\13]·· ' Read ADC
    · HIGH CS

    From there, you could change the last two bits accordingly to select the channel you would like. In the datesheet there is a truth table that will explain how to use this function; so you can make sure you have the proper channels selected to get the inforamtion from?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-20 21:32
    Your code says: IF (X1 - X0 = V) & (V > 400) THEN

    There are at least two problems with this. For one, you're using "&" which is a bit-wise AND operation when what you need to use is "AND" which is a logical test. Look in the BASIC Stamp Syntax and Reference Manual for a more detailed description of these operators. You can also look in the help files of the Stamp Editor.

    The 2nd problem is that you're testing for equality between X1 - X0 and V. Is that really what you want?

    I think what you want is: IF ABS(X1 - X0) > 400 THEN
Sign In or Register to comment.