간단한 제어: 가장 빠르게 시작할 수 있지만 FPS를 조정하려면 펌웨어를 다시 플래시해야 합니다.
시리얼 제어: 다시 플래시하지 않고도 주파수와 듀티 사이클을 실시간으로 조정할 수 있습니다 (장치의 전원이 꺼지면 설정이 초기화됩니다).
간단한 제어
시리얼 명령
#include <PWM.h>// Pin configurationint pin = 9; // Pinint value = 127; // Initial value for the PWM duty cycle// SET FREQUENCY HEREfloat frequency = 60; // Initial frequency in Hzvoid setup(){ // Initialize all timers except for timer0 to save timekeeping tasks InitTimersSafe(); // Set the initial PWM frequency and duty cycle if (SetPinFrequencySafe(pin, frequency)) { pwmWrite(pin, value); Serial.println("PWM frequency and initial duty cycle set."); } else { Serial.println("Failed to set frequency."); }}
#include <PWM.h>// Pin configurationint pin = 9; // Pinint value = 127; // Initial value for the PWM duty cyclefloat frequency = 60; // Initial frequency in Hzvoid setup(){ Serial.begin(9600); // Initialize all timers except for timer0 to save timekeeping tasks InitTimersSafe(); // Set the initial PWM frequency and duty cycle if (SetPinFrequencySafe(pin, frequency)) { pwmWrite(pin, value); Serial.println("PWM frequency and initial duty cycle set."); } else { Serial.println("Failed to set frequency."); }}void loop(){ if (Serial.available()) { // Read frequency and duty cycle values over Serial String inputString = Serial.readStringUntil('\n'); inputString.trim(); int freqDutySplitIndex = inputString.indexOf(','); if (freqDutySplitIndex != -1) { String freqStr = inputString.substring(0, freqDutySplitIndex); String dutyStr = inputString.substring(freqDutySplitIndex + 1); // Parse floats float newFrequency = freqStr.toFloat(); int newDutyCycle = dutyStr.toInt(); // Validate frequency range if (newFrequency >= 1 && newFrequency <= 2000000) { // Set the PWM frequency and apply duty cycle if (SetPinFrequencySafe(pin, newFrequency)) { value = map(constrain(newDutyCycle, 0, 100), 0, 100, 0, 255); pwmWrite(pin, value); Serial.print("Set frequency to: "); Serial.print(newFrequency); Serial.print(" Hz, duty cycle to: "); Serial.print(newDutyCycle); Serial.println("%"); } else { Serial.println("Failed to set new frequency."); } } else { Serial.println("Invalid frequency value."); } } else { Serial.println("Invalid input format. Use frequency,dutycycle (e.g., 60,50)."); } }}
이 코드를 사용하면 즉시 PWM 신호를 수정할 수 있습니다. 시리얼 모니터를 9600 보드레이트로 열고 {FREQUENCY},{DUTY_CYCLE} 형식으로 명령을 보내세요 (예: 60Hz, 50% 듀티 사이클의 경우 60,50).
사용할 두 카메라의 장치 ID를 식별한 다음, 현재 나열되어 있지 않은 장치 ID 번호를 선택하세요.이 예시에서는 위에 사용되지 않은 9를 사용하여 stellarHD_stitched라는 가상 장치를 생성합니다. 선택한 사용되지 않는 ID에 맞게 아래 명령의 9를 업데이트하세요: