W章で利用したプログラム

'-------------------------------------------------
'     円運動の加速度測定
'-------------------------------------------------
'
DECLARE SUB INITIALIZE ()
DECLARE SUB GRAPH ()
DECLARE FUNCTION END.FLAG ()
DECLARE SUB GRAPH2 ()
DECLARE SUB END.PROGRAM ()

CONST ZERO.HEX = 128, XO.T = 6, YO.T = 18, X.TIME = 1, X.VOLT = 57
CONST M.MAX = 70, X.LEN = M.MAX, Y.LEN = 14, END.TIME = 300
CONST SAMPLING.TIME = 8, LINE.COLOR = 1
DIM SHARED XV(0 TO 301), YV(0 TO 301), YA(0 TO 301)
CALL INITIALIZE

CLS
COLOR 7
LOCATE 6, 16: PRINT "==============================================="
COLOR 6
LOCATE 7, 16: PRINT "  遠心力(の加速度)と回転数を測定します"
COLOR 7
LOCATE 8, 16: PRINT "==============================================="
COLOR 7
LOCATE 12, 16: PRINT " INPUT1  SW1:STD SW2:MONO 回転数( 1 Hz/V)"
LOCATE 14, 16: PRINT " INPUT2  SW3:STD SW4:MONO 傾 き(10 °/V)"
BEEP: COLOR 23
LOCATE 23, 16: PRINT "準備ができましたら,リターンキーを押して下さい"
COLOR 7

DO
   IK$ = INKEY$
LOOP WHILE IK$ = ""

START:
SOKUTEI:

BEEP
CALL GRAPH
T = 0
LOCATE 2, X.TIME + 1: PRINT "開始の時刻="; : PRINT LEFT$(TIME$, SAMPLING.TIME)
FOR I = 0 TO 301
    XV(I) = 0: YV(I) = 0
NEXT

DO
   BEEP
   IK$ = INKEY$
   IF IK$ = "" THEN
      GOTO LAST.IF
   END IF
   IK = ASC(IK$)
   IF IK = &H52 OR IK = &H72 OR IK = &HBD THEN
      GOTO SOKUTEI
   ELSEIF IK = &H53 OR IK = &H73 OR IK = &HC4 THEN
      GOTO SOUKAN
   ELSEIF IK = &H45 OR IK = &H65 OR IK = &HB2 THEN
      GOTO SYURYOU
   END IF
LAST.IF:
   LOCATE 3, X.TIME + 1: PRINT "現在時刻 =";
   TIME0$ = MID$(TIME$, SAMPLING.TIME, 1)
   COLOR 2: PRINT LEFT$(TIME$, SAMPLING.TIME): COLOR 7
   
   PRINT #1, "b";
   ADUMMY$ = INPUT$(1, #1)
     PRINT #1, "i";
   LINE INPUT #1, AD$: AVT = VAL(AD$): ADUMMY$ = INPUT$(1, #1)
   AVT = AVT / 256 * 5
   XV(T) = AVT
   COLOR 2: LOCATE 2, X.VOLT + 12: PRINT USING "##.##"; AVT: COLOR 2
   CIRCLE ( XO + 8 * T / 6, YO - 48 * AVT), 1, 2
   PAINT (XO + 8 * T / 6, YO - 48 * AVT), 2
   
   PRINT #1, "a";
   BDUMMY$ = INPUT$(1, #1)
   PRINT #1, "i";
   LINE INPUT #1, BD$: BVT = VAL(BD$): BDUMMY$ = INPUT$(1, #1)
   BVT = BVT / 256 * 100
   YV(T) = BVT
   COLOR 3: LOCATE 3, X.VOLT + 12: PRINT USING "##.##"; BVT: COLOR 3
   CIRCLE ( XO + 8 * T / 6, YO - 2.4 * BVT), 1, 3
   'PAINT (XO + 8 * T / 6, YO - 2.4 * BVT), 3

   DO
   LOOP WHILE MID$(TIME$, SAMPLING.TIME, 1) = TIME0$
   T = T + 1
   IF T > END.TIME THEN
      GOTO MENU
   END IF
LOOP WHILE 1

MENU:
    DO
      BEEP
      IK$ = INKEY$
    LOOP WHILE IK$ = ""
      IK = ASC(IK$)
      IF IK = &H52 OR IK = &H72 OR IK = &HBD THEN
         GOTO SOKUTEI
      ELSEIF IK = &H53 OR IK = &H73 OR IK = &HC4 THEN
         GOTO SOUKAN
      ELSEIF IK = &H45 OR IK = &H65 OR IK = &HB2 THEN
         GOTO SYURYOU
      END IF

SOUKAN:
CALL GRAPH2
COLOR 6: LOCATE 22, 67: PRINT "R"; : COLOR 7: PRINT ":再測定"
COLOR 6: LOCATE 24, 67: PRINT "E"; : COLOR 7: PRINT ":終 了"
DO
   IK$ = INKEY$
LOOP WHILE IK$ = ""
IK = ASC(IK$)
IF IK = &H52 OR IK = &H72 OR IK = &HBD THEN
    GOTO SOKUTEI
ELSEIF IK = &H45 OR IK = &H65 OR IK = &HB2 THEN
    GOTO SYURYOU
END IF

SYURYOU:
CALL END.PROGRAM
END

FUNCTION END.FLAG
   LOCATE 24, 59: COLOR 18: PRINT "R"
   LOCATE 24, 73: COLOR 18: PRINT "E"
   COLOR 7
   DO
     DO
        BEEP
        IK$ = INKEY$
     LOOP WHILE IK$ = ""
     IK = ASC(IK$)
     IF IK = &H53 OR IK = &H73 OR IK = &HC4 THEN
        END.FLAG = 2
     ELSEIF IK = &H52 OR IK = &H72 OR IK = &HBD THEN
        END.FLAG = 1
        EXIT DO
     ELSEIF IK = &H45 OR IK = &H65 OR IK = &HB2 THEN
        END.FLAG = 0
        EXIT DO
      END IF
      IK$ = ""
   LOOP WHILE IK$ = ""
END FUNCTION

SUB END.PROGRAM
   BEEP: CLS
   PRINT #1, "d"; : PRINT #1, STR$(&H80)
   CLOSE #1
END SUB

SUB GRAPH

   SHARED XO, YO
   CLS
   XO = 131: YO = 296
   TITLE$ = "min"
   LINE (XO, YO)-(XO + 5 * 80, YO - 5 * 48), LINE.COLOR, B
   FOR I = 1 TO 9
      LINE (XO, YO - 24 * I)-(XO + 5 * 80, YO - 24 * I), LINE.COLOR, , &H8888
   NEXT
   FOR I = 1 TO 4
      LINE (XO + 80 * I, YO)-(XO + 80 * I, YO - 5 * 48), LINE.COLOR, , &H8888
   NEXT
   COLOR 7
   LOCATE 1, 29: PRINT "回転数と傾きの時間変化"
   
   COLOR 2
   LOCATE 5, 3: PRINT "回転数"
   LOCATE 6, 3: PRINT "(Hz)"
   FOR I = 1 TO 4
      LOCATE 19 - 3 * I, 5: PRINT USING "#.#"; I
   NEXT
   
   COLOR 3
   LOCATE 5, 11: PRINT "傾 き"
   LOCATE 6, 11: PRINT "(°)"
   FOR I = 1 TO 4
      LOCATE 19 - 3 * I, 13: PRINT USING "##"; 20 * I
   NEXT

   COLOR 7
   FOR I = 0 TO 5
      LOCATE 20, 17 + 10 * I: PRINT USING "#"; I
   NEXT
   LOCATE 22, 34: PRINT "経過時間 [ "; TITLE$; " ]"
   COLOR 7
   LOCATE 2, 60: PRINT "回転数 =   Hz"
   LOCATE 3, 60: PRINT "傾 き =   °"

   COLOR 7: LOCATE 24, 30: PRINT "相関グラフ "; : COLOR 2: PRINT "S";
   COLOR 7: PRINT "oukan  再実行 "; : COLOR 2: PRINT "R";
   COLOR 7: PRINT "etry  終了 "; : COLOR 2: PRINT "E"; : COLOR 7: PRINT "nd"
   COLOR 7
END SUB

SUB GRAPH2

   SHARED X1, Y1
   X1 = 131: Y1 = 344
   CLS
   LINE (X1, Y1)-(X1 + 20 * 16, Y1 - 20 * 16), LINE.COLOR, B
   FOR I = 1 TO 19
      LINE (X1, Y1 - 16* I)-(X1 + 20 * 16, Y1 - 16 * I), LINE.COLOR, , &H8888
   NEXT
   FOR I = 1 TO 19
      LINE (X1 + 16 * I, Y1)-(X1 + 16 * I, Y1 - 20 * 16), LINE.COLOR, , &H8888
   NEXT
   COLOR 7
   LOCATE 1, 21: PRINT "円運動と回転数と加速度の関係"
   LOCATE 5, 9: PRINT "加"
   LOCATE 8, 9: PRINT "速"
   LOCATE 11, 9: PRINT "度"
   LOCATE 14, 7: PRINT "(m/s )"
   LOCATE 24, 26: PRINT "回  転  数  (Hz)"
   FOR I = 1 TO 4
      LOCATE 22 - 5 * I, 15: PRINT USING "##"; 5 * I
   NEXT
   FOR I = 1 TO 4
      LOCATE 23, 16 + 10 * I: PRINT USING "#.#"; 5 * I
   NEXT
   FOR I = 0 TO 300
      YA(I) = 9.8 *TAN(YV(I) * 3.1416 / 180)
      CIRCLE (X1 + 160 * XV(I), Y1 - 16 * YA(I)), 3, 4
      PAINT (X1 + 160 * XV(I), Y1 - 16 * YA(I)), 4
   NEXT
END SUB

SUB INITIALIZE
   CLS
   VIEW PRINT 1 TO 25
   OPEN "COM1:9600,N,8,1,ASC" FOR RANDOM AS #1
END SUB


[目次へ]