本帖最後由 marlin12 於 2018-5-1 20:22 編輯
pulseIR用時間來計算,會計錯cycle。用delayMicroseconds來做間隔,大數值又唔準。不如試吓全部轉用cycle來計算,唔會計錯cycle,亦唔會有phase error。只需要用OSCCAL調準咗pulseIR,就全部野都準喇!
另外,將pulseIR變成inline,可減少被呼叫和返回時的延遲。- void SendNikonCode() {
- digitalWrite( LedPin, HIGH );
- pulseIR( 76, HIGH );
- pulseIR( 1064, LOW ); // no waveform (delay only)
- pulseIR( 15, HIGH );
- pulseIR( 60, LOW ); // no waveform (delay only)
- pulseIR( 15, HIGH );
- pulseIR( 136, LOW ); // no waveform (delay only)
- pulseIR( 15, HIGH );
- digitalWrite( LedPin, LOW );
- }
- inline void pulseIR( int cycles, int markLevel )
- {
- for( ; cycles > 0; cycles-- ) {
- digitalWrite( IrLedPin, markLevel );
- delayMicroseconds( 9 );
- digitalWrite( IrLedPin, LOW );
- delayMicroseconds( 8 );
- }
- }
複製代碼 |