Sub Process_Globals
Public Serial1 As Serial
Private freq As Byte
Private out As Pin
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
RunNative("pwm", Null)
out.Initialize(11, out.MODE_OUTPUT)
run
End Sub
Sub run
Do While True
Delay(200) 'duration of each frequency
freq=freq+10
If freq>244 Then freq=10
RunNative("frequency", Null)
Loop
End Sub
#if C
void pwm (B4R::Object* o) {
//timer2 settings
OCR2A = 127;
TCCR2A = 0b1000011; //toggle output, fast PWM mode
TCCR2B = 0b1011; // fast PWM mode, prescale 1:64
}
void frequency (B4R::Object* o) {
OCR2A=b4r_main::_freq;
}
#End if