Shop OBEX P1 Docs P2 Docs Learn Events
Main program direction — Parallax Forums

Main program direction

Brian CarpenterBrian Carpenter Posts: 728
edited 2005-09-03 15:06 in BASIC Stamp
here is the current main menu

Main:
· GOSUB ADCChip
· GOSUB Memsic
· GOSUB Level
· GOSUB MotorVoltage
GOTO Main

but i only want it to do MotorVotage every 6th time through the cycle.· Any ideas?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


It's Only A Stupid Question If You Have Not Googled It First!!

Comments

  • cyberbiotacyberbiota Posts: 79
    edited 2005-09-03 08:46
    Embed a Counter in the "Level" subroutine such that it increments with each pass through "Level." Test for If Counter<5, GOTO Main. Zero Counter in "Motorvoltage." Program flow should be Main->ADCChip->Memsic->Level->Main for 5 iterations, then Main->ADCChip->Memsic->Level->MotorVoltage->Main for the sixth, at which point Counter will be re-zeroed, and the cycle will repeat.

    peter

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Peter C. Charles

    Director, Research and Technology
    CyberBiota, Incorporated
    Peter.charles@cyberbiota.com
    http://www.cyberbiota.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-03 12:46
    Here's how I do that:

    Main:
    · DO
    ····cycles =·cyles + 1 // 6
    ··· GOSUB ADCChip
    ·· ·GOSUB Memsic
    ·· ·GOSUB Level
    ····IF (cycles = 0) THEN
    ····· GOSUB MotorVoltage
    ··· ENDIF
    · LOOP

    The // (modulus) operator is vastly underutilized, and I find it much cleaner that IF-THEN logic for things like this.· Using // as I have above will force cycles to count from 0 to 5 and wrap back around.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-09-03 15:06
    cyberbiota, thank you for you help

    Jon, thanks again. you definatly get around. i think that youu have answered evey one of my posts. that is very appriciated.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
Sign In or Register to comment.