Need help with the code and initializing a microchip. Looking to use a MCU IC ATTiny414 to modulate an IR led signal at 38Khz, pulsed at 600us on and 900us off.
Is this the general Idea?
- Init the chip/timer of to 38Khz
- Set the output pin High at that frequency
- delay for 600us
- Set the pin Low
- delay for 900us
Can’t find any exact matches as suggestions to code this. So I’m trying to piece together solutions from here and others. Need help adapting the set up (that code is for an Uno I believe. I HAVE to use a ATtiny412 for this project.
556-ATTINY412-SSNR - 8-bit Microcontrollers - MCU 105C, 5.5V, Green, 20MHz, SOIC8, T&R
Mouser Datasheet: mouser.com/datasheet/2/268/40001911A-1220759.pdf
What I have so far…IF this is the right approach:
const byte IRLED = 2; // Timer 2 "A" output: OC2A
void setup() {
pinMode (IRLED, OUTPUT);
// set up Timer for 38khz - *NEED* BIG HELP understanding how to adapt this code for Arduino //(N.Gammon) to a ATtiny414 MCU IC
TCCR2A = _BV (COM2A0) | _BV(WGM21); // CTC, toggle OC2A on Compare Match
TCCR2B = _BV (CS20); // No prescaler
OCR2A = 209; // compare A register value (210 * clock speed)
// = 13.125 nS , so frequency is 1 / (2 * 13.125) = 38095
} // end of setup
void loop() {
//the IR receiver is expecting “on” 600us and “off” 900us
digitalWrite(IRLED, HIGH); //turn on the IR LED
delayMicroseconds(900);
digitalWrite(IRLED, LOW); //turn off the IR LED
delayMicroseconds(600);
} //end of loop
Should go without saying that I am an artist not an engineer, so please help with that in mind.