You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code provided in the rs-blinker.ino does not work on my Elegoo Mega 2560 R3. It did not switch the LED. After a bit of tweaking I got it working, code below.
Question. Do you see any faults on this code that may not yield the intended results?
#defineLED_PIN 2 // Pin number for the onboard LED (Arduino Uno)
constunsigned long longfreq=50; // So I can see itvoidsetup() {
pinMode(LED_PIN, OUTPUT); // Set the LED pin as output// Configure Timer1cli(); // Disable global interruptsTCCR1A=0; // Set Timer1 to Normal mode (no PWM)TCCR1B=0; // Clear Timer1 control register B// Set compare match register for 1Hz (1-second interval)// OCR1A = 15624; // (16 MHz / (1024 * 1Hz)) - 1OCR1A= (F_CPU) / (1024*freq) -1;
// Set prescaler to 1024 and enable CTC modeTCCR1B |= (1 << WGM12); // Configure for CTC modeTCCR1B |= (1 << CS12) | (1 << CS10); // Set prescaler to 1024// Enable Timer1 compare interruptTIMSK1 |= (1 << OCIE1A);
sei(); // Enable global interrupts
}
// Interrupt Service Routine for Timer1 Compare Match AISR(TIMER1_COMPA_vect) {
digitalWrite(LED_PIN, !digitalRead(LED_PIN)); // Toggle LED
}
voidloop() {}
The text was updated successfully, but these errors were encountered:
The code provided in the
rs-blinker.ino
does not work on my Elegoo Mega 2560 R3. It did not switch the LED. After a bit of tweaking I got it working, code below.Question. Do you see any faults on this code that may not yield the intended results?
The text was updated successfully, but these errors were encountered: