#define LOW_FREQ 1.0f // 1.0f Hz does not produce output, 10.0f Hz produces blinking LED
int led_onboard_pin = 13; // teensy-lc LED0
int ctrl_pin_lofreq = 6; // FTM0, teensy-lc 6,9,10,20,22 or 23
void setup()
{
Serial.begin(9600);
reinit();
}
void reinit()
{
pinMode(led_onboard_pin , OUTPUT);
pinMode(ctrl_pin_lofreq, OUTPUT);
analogWriteResolution(16);
analogWriteFrequency(ctrl_pin_lofreq, LOW_FREQ);
analogWrite(ctrl_pin_lofreq, 32768);
Serial.println("Initialized");
}
void loop() {
char b;
// Check "frequency" output and reproduce it on LED
if (digitalRead(ctrl_pin_lofreq)) {
digitalWrite(led_onboard_pin, HIGH);
} else {
digitalWrite(led_onboard_pin, LOW);
}
// Handle USB Serial
if (Serial.available()) {
b = Serial.read();
if (b == 'r') {
reinit();
}
if (b == 's') {
Serial.print("IRC is ");
if (MCG_S & 1) {
Serial.println("4 MHz");
} else {
Serial.println("32 kHz");
}
Serial.print("MCG_C1 = ");
Serial.println((int)(MCG_C1 & 0xFF)); // 32 = 0x20 = 0b0010.0000 : 00b ClkSrc FLL/PLL, 100b div16, extref, MCGIRCLK inactive,
}
}
}