Crazy project called Arduino Tormentor. I found the program below that puts out for IR on pin 3 but should work feeding an ultra sound transducer. If I use an OCR2A = 50, frequency = 39216 Hz and the OCR2A = 48, frequency = 40816 Hz for another output pin for a 2nd transducer. Kind of like a directional speaker in a museum where you can only hear the story about a painting only while standing in front of it. So if I point this directly at a person they would hear a 1600hz tone and nobody around them will. I'm just learning Arduino and not sure about the variable names for the 2nd output and any assistance would be greatly appreciated. Thank you.
volatile byte pulse = 0;
ISR(TIMER2_COMPB_vect){ // Interrupt service routine to pulse the modulated pin 3
pulse++;
if(pulse >= 8) { // change number for number of modulation cycles in a pulse
pulse =0;
TCCR2A ^= _BV(COM2B1); // toggle pin 3 enable, turning the pin on and off
}
}
void setIrModOutput(){ // sets pin 3 going at the IR modulation rate
pinMode(3, OUTPUT);
TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); // Just enable output on Pin 3 and disable it on Pin 11
TCCR2B = _BV(WGM22) | _BV(CS22);
OCR2A = 51; // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz
OCR2B = 26; // deines the duty cycle - Half the OCR2A value for 50%
TCCR2B = TCCR2B & 0b00111000 | 0x2; // select a prescale value of 8:1 of the system clock
}
void setup(){
setIrModOutput();
TIMSK2 = _BV(OCIE2B); // Output Compare Match B Interrupt Enable
}
void loop(){
// do something here
If only you had used code tags ...????? I did not write it but as I said I found the program. It was found right on this forum. I was looking for help, not an unneeded comment about somebody else s coding skills.
It's not about the coding, it's about how you post on this forum. It is explained in the locked posts at the head of the forum. Some posters READ before they attempt to write.
I read it and I do not see what you are talking about. What is wrong with my post? I did it as a new post and I think it is in the right section. Why would you need to insert smiley faces in my message?
Why would you need to insert smiley faces in my message?
I assume that this accusation was directed at me. I did not insert the smiley face. Look at your original post. The smiley is already there. Using code tags would have prevented that happening.
Thank you for the help. I guess I missed the </> part in the instructions. I edited the original post and I now understand. I did not know the smiley faces were automatic. I thought somebody was messing with a first time poster. It would have been easier if someone would have explained it in the beginning instead of just saying read the instructions.