bool started = false; // 測定開始フラグ
    int indx = 0; // 記録するデーターのインデックス

    while (true) {
        t0flag = 0;
        while (t0flag == 0) { // タイマー割り込みを待つ
            delay(0);
        }
        int ch1Vsense[2] = {0};
        dataread(DEVID, PAC1710::REG::C1_SVRES_H, ch1Vsense, 2);

        if (!started) {
            // 電流値がしきい値(startthreshold)未満だったら、測定を始めない
            if (amp > -startthreshold && amp < startthreshold) {
                continue;
            }
            started = true; // 電流値がしきい値を超えたら測定開始
        }
        ampbuf[indx] = amp; // 電流値をメモリーに記録する
        if (++indx >= NSAMPLES) { // データー数がサンプル数を超えたら、周期処理を終わる
            break;
        }
    }