<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: 'Calibri'; COLOR: #000000">
<DIV>For the trigger pull you can easily check and debounce in software. </DIV>
<DIV>I had wrote the following for a toy gun I retro fitted to make noise and 
blink, which gives good feedback for trigger pulls, but could easily be changed 
to also give feedback for hits also. It is written to start and play through a 
tigger pull sequence when the trigger is pulled before the next detect of the 
trigger, but could be changed to enable the trigger detection quicker. It was 
written to allow multiple sequences of pin changes to run based on events. I 
used a tiny84 to get more pins. The speaker I used was an old one from an over 
the ear type headphones, just connected to a pin and ground. The tiny did not 
have a sound library when written, maybe not still, so I just bit banged the 
pin, and came up with a spacey sound so it worked, just not quite as loud as the 
Aurdino with the sound library. Driving all the leds and the speaker did require 
a cap on the power supply pin. Might give you some ideas. </DIV>
<DIV> </DIV>
<DIV dir=ltr><FONT face="Times New Roman">#define tonePin 8<BR>#define pushPin 
10<BR>#define num_lights 9<BR>#define num_notes 12<BR><BR>unsigned long last = 
0;<BR><BR>// tone stuff<BR>typedef struct tones<BR>{<BR>    int 
freq;<BR>    int dur; <BR>};<BR>int   note_count = 
0;<BR>int   note_index = 0;<BR>tones notes[num_notes];<BR><BR>// led 
stuff<BR>typedef struct leds<BR>{<BR>    unsigned long 
pattern;<BR>    unsigned long trig_pattern;<BR>    
int           
pin;<BR>};<BR><BR>unsigned int count = 0;<BR>unsigned int pos = 0;<BR>leds 
lights[num_lights];<BR><BR>// button stuff<BR>boolean triggered = 
false;<BR><BR>void check_button()<BR>{<BR>    // triggered is 
cleared when the tone stops a cycle<BR>    if ( ! 
triggered)<BR>    {<BR>        
triggered = digitalRead(pushPin);<BR>        
if (triggered) pos = 0;<BR>    }<BR>}<BR><BR>void 
process_lights()<BR>{<BR>    count++;<BR>    if 
(count < 10) return;<BR>      <BR>    
count = 0;<BR>    pos++;<BR>    if (pos >= 32) 
pos = 0;<BR>    unsigned long tmp = 1; <BR>    tmp 
= tmp << pos;<BR>    <BR>    for(int i = 0; 
i < num_lights; i++)<BR>    {      
<BR>        unsigned long state = 
lights[i].pattern & tmp;<BR>        if 
(triggered)<BR>        
{<BR>            state = 
lights[i].trig_pattern & tmp;<BR>        
}<BR>        
<BR>        if (state != 
0)<BR>        
{<BR>            
digitalWrite(lights[i].pin, HIGH);<BR>        
}<BR>        
else<BR>        
{<BR>            
digitalWrite(lights[i].pin, LOW);<BR>        
}<BR>    }    <BR>}<BR><BR>void 
process_tone()<BR>{<BR>    if ( ! 
triggered)<BR>    {<BR>        
note_count = 0;<BR>        note_index = 
0;<BR>    }<BR>    else<BR>    
{<BR>        if 
(note_count%(2*notes[note_index].freq) < 
notes[note_index].freq)<BR>        
{<BR>            
digitalWrite(tonePin, HIGH);<BR>        
}<BR>        
else<BR>        
{<BR>            
digitalWrite(tonePin, LOW); <BR>        
}<BR>        
note_count++;<BR>        if (note_count >= 
notes[note_index].dur)<BR>        
{<BR>            
note_index++;<BR>            
note_count = 
0;<BR>            if 
(note_index >= 
num_notes)<BR>            
{<BR>                
triggered = 
false;<BR>                
digitalWrite(tonePin, 
LOW);<BR>                
note_count = 
0;<BR>                
note_index = 
0;<BR>            
}<BR>        }<BR>    
}<BR>}<BR><BR>void setup()<BR>{    <BR>    
unsigned long one = 1;<BR>    lights[0].pattern = 
one;<BR>    lights[0].trig_pattern = 
0xfc000000;<BR>    lights[0].pin = 0;<BR>    
<BR>    lights[1].pattern = one << 5;<BR>    
lights[1].trig_pattern = 0x03f00000;<BR>    lights[1].pin = 
1;<BR> <BR>    lights[2].pattern = one << 
10;<BR>    lights[2].trig_pattern = 
0x000fc000;<BR>    lights[2].pin = 2;<BR>    
<BR>    lights[3].pattern = one << 
16;<BR>    lights[3].trig_pattern = 
0x000fc000;<BR>    lights[3].pin = 3;<BR>    
<BR>    lights[4].pattern = one << 
21;<BR>    lights[4].trig_pattern = 
0x000003f00;<BR>    lights[4].pin = 4;<BR>    
<BR>    lights[5].pattern = one << 
27;<BR>    lights[5].trig_pattern = 
0x000000ff;<BR>    lights[5].pin = 5;<BR>    
<BR>    lights[6].pattern = 0xf0f0f0f0;<BR>    
lights[6].trig_pattern = 0x00ffff00;<BR>    lights[6].pin = 
6;<BR>    <BR>    lights[7].pattern = 
0x0f0f0f0f;<BR>    lights[7].trig_pattern = 
0xffff0000;<BR>    lights[7].pin = 7;<BR>    
<BR>    lights[8].pattern = 0xffffffff;<BR>    
lights[8].trig_pattern = 0x0000ffff;<BR>    lights[8].pin = 
9;<BR>    <BR>    for(int i = 0; i < 
num_lights; i++)<BR>    
{<BR>        pinMode(lights[i].pin, 
OUTPUT);<BR>        
digitalWrite(lights[i].pin, HIGH);<BR>    }<BR>    
delay(500);<BR>    for(int i = 0; i < num_lights; 
i++)<BR>    {<BR>        
digitalWrite(lights[i].pin, LOW);<BR>    }</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman"> <BR>    notes[0].freq 
= 9;<BR>    notes[0].dur  = 50;<BR>    
notes[1].freq = 3;<BR>    notes[1].dur  = 
60;<BR>    notes[2].freq = 5;<BR>    
notes[2].dur  = 100;<BR>    notes[3].freq = 
7;<BR>    notes[3].dur  = 80;    
<BR> <BR>    notes[4].freq = 9;<BR>    
notes[4].dur  = 70;<BR>    notes[5].freq = 
10;<BR>    notes[5].dur  = 60;<BR>    
notes[6].freq = 1;<BR>    notes[6].dur  = 
50;<BR>    notes[7].freq = 3;<BR>    
notes[7].dur  = 50;    <BR> <BR>    
notes[8].freq = 5;<BR>    notes[8].dur  = 
50;<BR>    notes[9].freq = 7;<BR>    
notes[9].dur  = 50;<BR>    notes[10].freq = 
9;<BR>    notes[10].dur  = 50;<BR>    
notes[11].freq = 1;<BR>    notes[11].dur  = 60;  
<BR>    <BR>    
pinMode(tonePin,OUTPUT);<BR>    <BR>    
pinMode(pushPin,INPUT);<BR>}<BR><BR>void loop()<BR>{<BR>    
unsigned long now = millis();<BR><BR>    if (now >= last + 
1)<BR>    {<BR>        last = 
now;<BR>        
check_button();<BR>        
process_lights();<BR>        
process_tone();<BR>    } <BR>}</FONT><BR></DIV>
<DIV 
style='FONT-SIZE: small; TEXT-DECORATION: none; FONT-FAMILY: "Calibri"; FONT-WEIGHT: normal; COLOR: #000000; FONT-STYLE: normal; DISPLAY: inline'>
<DIV style="FONT: 10pt tahoma">
<DIV><FONT size=3 face=Calibri></FONT> </DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=joe@fairanswers.com 
href="mailto:joe@fairanswers.com">Joe Fair</A> </DIV>
<DIV><B>Sent:</B> Thursday, July 31, 2014 7:14 PM</DIV>
<DIV><B>To:</B> <A title=jonjwolfe@yahoo.com 
href="mailto:jonjwolfe@yahoo.com">Jon Wolfe</A> </DIV>
<DIV><B>Cc:</B> <A title=triembed@triembed.org 
href="mailto:triembed@triembed.org">triembed@triembed.org</A> </DIV>
<DIV><B>Subject:</B> Re: [TriEmbed] IR sensor vs trigger</DIV></DIV></DIV>
<DIV> </DIV></DIV>
<DIV 
style='FONT-SIZE: small; TEXT-DECORATION: none; FONT-FAMILY: "Calibri"; FONT-WEIGHT: normal; COLOR: #000000; FONT-STYLE: normal; DISPLAY: inline'>
<P>I think you are right, they kind of each need a chip.  I was hoping to 
be smart enough to not to need more hardware. <BR>Does the tiny sport two 
interrupts?  Or maybe i can tie them together?</P>
<P>I guess i need to learn more about days sheets, too.<BR>Joe</P>
<DIV class=gmail_quote>On Jul 30, 2014 10:09 PM, "Jon Wolfe" <<A 
href="mailto:jonjwolfe@yahoo.com">jonjwolfe@yahoo.com</A>> wrote:<BR 
type="attribution">
<BLOCKQUOTE class=gmail_quote 
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
  <DIV>
  <DIV 
  style="FONT-SIZE: 10pt; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: #000; BACKGROUND-COLOR: #fff">
  <DIV><SPAN>I agree with the others, it sounds like the trigger should get the 
  interrupt.</SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><BR><SPAN></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><SPAN>Like 
  Jeff said, you want your interrupt to execute in as short of a time as 
  possible. One approach might be to just set a flag on trigger presses then 
  process the action in the main loop. That could still leave you with 1 sec 
  latency if you are detecting IR hits, which would probably be pretty 
  noticeable.</SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><BR><SPAN></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><SPAN>I 
  have never tried this on a tiny, but I'm making it a personal mission to find 
  a use case for it, but you could use an RTOS, like <A 
  href="http://www.femtoos.org/" target=_blank>http://www.femtoos.org/</A>  
  Looks promising. I've used ChibiOS on Cortex M3/4's and found it pretty nice 
  to work with, YMMV. <BR></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><SPAN><BR></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><SPAN>The 
  other alternative approaches might be to try to reduce the 1 second detection 
  loop. Or, to try to architect your own "cooperative multitasking" or 
  coroutines. In short, write your detect loop so that instead of looping for 1 
  second, it just does a little bit of work and returns to the main loop, 
  remembering where is was in the loop between each call. I use this approach a 
  lot.</SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><BR><SPAN></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><SPAN>I 
  will say that you should try to handle debouncing the trigger in hardware as 
  much as you can. I've tried software debouncing mechanical encoders in 
  interrupt driven routines, and I can attest that it is maddening.</SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><BR><SPAN></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><SPAN>Lastly, 
  you *could* always just buy a separate tiny for the detection, but I have no 
  ulterior motive or bias there ;)</SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><BR><SPAN></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><BR><SPAN></SPAN></DIV>
  <DIV 
  style="FONT-SIZE: 13px; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif; COLOR: rgb(0,0,0); FONT-STYLE: normal; BACKGROUND-COLOR: transparent"><SPAN><BR></SPAN></DIV>
  <DIV> </DIV>
  <DIV 
  style="FONT-SIZE: 10pt; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif">
  <DIV 
  style="FONT-SIZE: 12pt; FONT-FAMILY: helveticaneue,helvetica neue,helvetica,arial,lucida grande,sans-serif">
  <DIV dir=ltr>
  <HR SIZE=1>
  <FONT face=Arial><B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Joe Fair 
  <<A href="mailto:joe@fairanswers.com" 
  target=_blank>joe@fairanswers.com</A>><BR><B><SPAN 
  style="FONT-WEIGHT: bold">To:</SPAN></B> <A 
  href="mailto:triembed@triembed.org" target=_blank>triembed@triembed.org</A> 
  <BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Saturday, July 26, 
  2014 4:09 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> 
  [TriEmbed] IR sensor vs trigger<BR></FONT></DIV>
  <DIV>
  <DIV> </DIV>
  <DIV>
  <DIV>Ok.  I'm pretty close on getting my home made laser tag with at tiny 
  85s going, but now i have a question about design.</DIV>
  <DIV>The loop I'm using detects a trigger pull, then a hit on the 
  sensors.  however, The pulse in function I'm using to sense IR ha a 
  timeout of 1 second.  If there is no inbound signal it is only checking 
  got a trigger pull once a second.</DIV>
  <DIV>So i need to use an interrupt, but does it matter if i use one on the 
  trigger pull or the ir sensor? </DIV>
  <DIV>Joe<BR></DIV></DIV><BR>_______________________________________________<BR>Triangle, 
  NC Embedded Computing mailing list<BR><A href="mailto:TriEmbed@triembed.org" 
  target=_blank>TriEmbed@triembed.org</A><BR><A 
  href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" 
  target=_blank>http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</A><BR>TriEmbed 
  web site: <A href="http://triembed.org/" 
  target=_blank>http://TriEmbed.org</A><BR><BR><BR></DIV></DIV></DIV></DIV></DIV></BLOCKQUOTE></DIV>
<P>
<HR>
_______________________________________________<BR>Triangle, NC Embedded 
Computing mailing 
list<BR>TriEmbed@triembed.org<BR>http://mail.triembed.org/mailman/listinfo/triembed_triembed.org<BR>TriEmbed 
web site: http://TriEmbed.org<BR></DIV></DIV></DIV></BODY></HTML>