<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=30&amp;t=10170&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2015-01-12T14:51:44+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=30&amp;t=10170&amp;mode</id>
<entry>
<author><name><![CDATA[bigplik]]></name></author>
<updated>2015-01-12T14:51:44+01:00</updated>
<published>2015-01-12T09:15:14+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=10170&amp;p=113833#p113833</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=10170&amp;p=113833#p113833"/>
<title type="html"><![CDATA[ADXL 345 - detekcja pojedyńczego i podwójnego stuknięcia]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=10170&amp;p=113833#p113833"><![CDATA[
Witam,<br />Znalazłem na forum arduino.cc kod na detekcję pojedyńczego lub podwójnego stuknięcia w akcelerometr<br /><a href="http://forum.arduino.cc/index.php?topic=270406.0"  class="postlink">topic</a><br /><br />Tak jak tam używam biblioteki &lt;ADXL345.h&gt;:<br /><a href="https://github.com/adafruit/Adafruit_ADXL345"  class="postlink">https://github.com/adafruit/Adafruit_ADXL345</a><br />i tego kodu:<br /><br />[syntax=c]&#91;i&#93;//Arduino 1.0+ Only!<br /><br />#include &lt;Wire.h&gt;<br />#include &lt;ADXL345.h&gt;<br /><br /><br />ADXL345 adxl; //variable adxl is an instance of the ADXL345 library<br /><br />void setup(){<br />  Serial.begin(9600);<br />  adxl.powerOn();<br />  <br />  //set activity/ inactivity thresholds (0-255)<br />  adxl.setActivityThreshold(75); //62.5mg per increment<br />  adxl.setInactivityThreshold(75); //62.5mg per increment<br />  adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?<br /> <br />  //look of activity movement on this axes - 1 == on; 0 == off <br />  adxl.setActivityX(1);<br />  adxl.setActivityY(1);<br />  adxl.setActivityZ(1);<br /> <br />  //look of inactivity movement on this axes - 1 == on; 0 == off<br />  adxl.setInactivityX(1);<br />  adxl.setInactivityY(1);<br />  adxl.setInactivityZ(1);<br /> <br />  //look of tap movement on this axes - 1 == on; 0 == off<br />  adxl.setTapDetectionOnX(0);<br />  adxl.setTapDetectionOnY(0);<br />  adxl.setTapDetectionOnZ(1);<br /> <br />  //set values for what is a tap, and what is a double tap (0-255)<br />  adxl.setTapThreshold(50); //62.5mg per increment<br />  adxl.setTapDuration(15); //625?s per increment<br />  adxl.setDoubleTapLatency(80); //1.25ms per increment<br />  adxl.setDoubleTapWindow(200); //1.25ms per increment<br /> <br />  //set values for what is considered freefall (0-255)<br />  adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment<br />  adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment<br /> <br />  //setting all interupts to take place on int pin 1<br />  //I had issues with int pin 2, was unable to reset it<br />  adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,   ADXL345_INT1_PIN );<br />  adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,   ADXL345_INT1_PIN );<br />  adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,    ADXL345_INT1_PIN );<br />  adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,     ADXL345_INT1_PIN );<br />  adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,   ADXL345_INT1_PIN );<br /> <br />  //register interupt actions - 1 == on; 0 == off  <br />  adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);<br />  adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);<br />  adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT,  1);<br />  adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT,   1);<br />  adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);<br />}<br /><br />void loop(){<br />  <br />  //Boring accelerometer stuff   <br />  int x, y, z;  <br />  adxl.readAccel(&amp;x, &amp;y, &amp;z); //read the accelerometer values and store them in variables  x,y,z<br /><br />  // Output x,y,z values - Commented out<br />  Serial.print(x);<br />  Serial.print(y);<br />  Serial.println(z);<br /><br />  <br />  //Fun Stuff!    <br />  //read interrupts source and look for triggerd actions<br />  <br />  //getInterruptSource clears all triggered actions after returning value<br />  //so do not call again until you need to recheck for triggered actions<br />   byte interrupts = adxl.getInterruptSource();<br />  <br />  // freefall<br />  if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){<br />    Serial.println(&quot;freefall&quot;);<br />    //add code here to do when freefall is sensed<br />  } <br />  <br />  //inactivity<br />  if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){<br />    Serial.println(&quot;inactivity&quot;);<br />     //add code here to do when inactivity is sensed<br />  }<br />  <br />  //activity<br />  if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){<br />    Serial.println(&quot;activity&quot;); <br />     //add code here to do when activity is sensed<br />  }<br />  <br />  //double tap<br />  if(adxl.triggered(interrupts, ADXL345_DOUBLE_TAP)){<br />    Serial.println(&quot;double tap&quot;);<br />     //add code here to do when a 2X tap is sensed<br />  }<br />  <br />  //tap<br />  if(adxl.triggered(interrupts, ADXL345_SINGLE_TAP)){<br />    Serial.println(&quot;tap&quot;);<br />     //add code here to do when a tap is sensed<br />  } <br /><br />}&#91;/i&#93;[/syntax]<br /><br />Co można zauważć w serial monitorze to detekcja &quot;double tap&quot;. Tzn. arduino odczytuje &quot;double tap&quot; ale zaraz potem odczytuje ponownie &quot;single tap&quot;.<br />Tak więc cokolwiek chciałbym napisać w sekcji &quot;double tap&quot; nie działa bo program od razu zamienia to na to co jest napisane w sekcji &quot;single tap&quot;.<br />Tak więc w serial monitorze w przypadku detekcji &quot;single tap&quot; odczytuje on &quot;single tap&quot; a w przypadku detekcji &quot;double tap&quot; odcztuje w pierwszej lini &quot;double tap&quot; i od razu w lini pod spodem wyświetla &quot;single tap&quot;.<br /><br />Czy może ktoś pomóc wyczyścić ten kod? <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=6631">bigplik</a> — 12 sty 2015, o 09:15</p><hr />
]]></content>
</entry>
</feed>