├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── custom.md │ └── feature_request.md └── workflows │ ├── run-ci-arduino.yml │ ├── stale.yml │ └── sync_issues.yml ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── License.txt ├── README.md ├── examples └── pedometer │ └── pedometer.ino ├── pedometer.cpp └── pedometer.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/run-ci-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Run Ci Arduino 2 | 3 | on: 4 | push: 5 | pull_request: 6 | repository_dispatch: 7 | types: [trigger-workflow] 8 | 9 | jobs: 10 | ci-arduino: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v4 16 | 17 | - name: Checkout script repository 18 | uses: actions/checkout@v4 19 | with: 20 | repository: Seeed-Studio/ci-arduino 21 | path: ci 22 | 23 | - name: Setup arduino cli 24 | uses: arduino/setup-arduino-cli@v2.0.0 25 | 26 | - name: Create a depend.list file 27 | run: | 28 | # eg: echo "" >> depend.list 29 | echo "Seeed-Studio/Seeed_Arduino_ADXL345" >> depend.list 30 | echo "Seeed-Studio/Grove_Current_Sensor" >> depend.list 31 | 32 | - name: Create a ignore.list file 33 | run: | 34 | # eg: echo "," >> ignore.list 35 | 36 | - name: Build sketch 37 | run: ./ci/tools/compile.sh 38 | 39 | - name: Build result 40 | run: | 41 | cat build.log 42 | if [ ${{ github.event_name }} == 'pull_request' ] && [ -f compile.failed ]; then 43 | exit 1 44 | fi 45 | 46 | - name: Generate issue 47 | if: ${{ github.event_name != 'pull_request' }} 48 | run: ./ci/tools/issue.sh 49 | env: 50 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 51 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: 'Close stale issues and PRs' 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '0 4 * * *' 7 | 8 | jobs: 9 | stale: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v4 15 | 16 | - name: Checkout script repository 17 | uses: actions/checkout@v4 18 | with: 19 | repository: Seeed-Studio/sync-github-all-issues 20 | path: ci 21 | 22 | - name: Run script 23 | run: ./ci/tools/stale.sh 24 | env: 25 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/sync_issues.yml: -------------------------------------------------------------------------------- 1 | name: Automate Issue Management 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - assigned 9 | - unassigned 10 | - labeled 11 | - unlabeled 12 | - reopened 13 | 14 | jobs: 15 | add_issue_to_project: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Add issue to GitHub Project 19 | uses: actions/add-to-project@v1.0.2 20 | with: 21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17 22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }} 23 | labeled: bug 24 | label-operator: NOT -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: generic 2 | dist: bionic 3 | sudo: false 4 | cache: 5 | directories: 6 | - ~/arduino_ide 7 | - ~/.arduino15/packages/ 8 | 9 | before_install: 10 | - wget -c https://github.com/Seeed-Studio/Seeed_Arduino_atUnified/raw/master/seeed-arduino-ci.sh 11 | 12 | script: 13 | - chmod +x seeed-arduino-ci.sh 14 | - cat $PWD/seeed-arduino-ci.sh 15 | - bash $PWD/seeed-arduino-ci.sh 16 | nothing 17 | Seeed-Studio/Seeed_Arduino_ADXL345.git Seeed-Studio/Grove_Current_Sensor.git 18 | 19 | notifications: 20 | email: 21 | on_success: change 22 | on_failure: change 23 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at zuobaozhu@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing guidelines 2 | 3 | All guidelines for contributing to the Seeed_Arduino_Pedometer repository can be found at [`How to contribute guideline`](https://github.com/Seeed-Studio/Seeed_Arduino_Pedometer/wiki/How_to_contribute). 4 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Seeed Technology Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pedometer 2 | ------------------------------------------------------------- 3 | ![Magic Bracelet](http://www.instructables.com/files/orig/FFC/4J92/HSVT9BUR/FFC4J92HSVT9BUR.jpg) 4 | 5 | this is a easy pedometer made by using seeed Xadow products, have fun! 6 | 7 |
8 | ### Introduction: 9 | We had an instructable about how to make a pedometer, for more information, please refer to [DIY your own pedometer with Seeed Xadow products](http://www.instructables.com/id/DIY-your-own-pedometer-with-Seeed-Xadow-products/) 10 | 11 | 12 |
13 | ---- 14 | 15 | This software is written by lawliet zou (![](http://www.seeedstudio.com/wiki/images/f/f8/Email-lawliet.zou.jpg)) for [Seeed Technology Inc.](http://www.seeed.cc) and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt/LICENSE for the details of MIT license.
16 | 17 | Contributing to this software is warmly welcomed. You can do this basically by
18 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
19 | for operating guide). Adding change log and your contact into file header is encouraged.
20 | Thanks for your contribution. 21 | 22 | Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond. 23 | 24 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Pedometer)](https://github.com/igrigorik/ga-beacon) 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/pedometer/pedometer.ino: -------------------------------------------------------------------------------- 1 | #include "pedometer.h" 2 | #include 3 | #include 4 | #include 5 | 6 | Pedometer pedometer; 7 | 8 | void setup(){ 9 | Serial.begin(9600); 10 | oledInit(); 11 | pedometer.init(); 12 | } 13 | 14 | 15 | void loop(){ 16 | pedometer.stepCalc(); 17 | SeeedOled.setTextXY(5,10); 18 | char number[2]; 19 | SeeedOled.putString(itoa(pedometer.stepCount,number,10)); //Print the String 20 | } 21 | 22 | void oledInit(){ 23 | //oled init 24 | Wire.begin(); 25 | SeeedOled.init(); //initialze SEEED OLED display 26 | #if defined(ARDUINO_ARCH_AVR) 27 | DDRB|=0x21; //digital pin 8, LED glow indicates Film properly Connected . 28 | PORTB |= 0x21; 29 | #endif 30 | 31 | SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner 32 | SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode) 33 | SeeedOled.setPageMode(); //Set addressing mode to Page Mode 34 | SeeedOled.setTextXY(0,0); 35 | SeeedOled.putString("****************"); 36 | SeeedOled.setTextXY(1,0); 37 | SeeedOled.putString("** PEDOMETER **"); 38 | SeeedOled.setTextXY(2,0); 39 | SeeedOled.putString("****************"); 40 | SeeedOled.setTextXY(3,0); 41 | SeeedOled.putString("*"); 42 | SeeedOled.setTextXY(3,15); 43 | SeeedOled.putString("*"); 44 | SeeedOled.setTextXY(4,0); 45 | SeeedOled.putString("*"); 46 | SeeedOled.setTextXY(4,15); 47 | SeeedOled.putString("*"); 48 | SeeedOled.setTextXY(5,0); 49 | SeeedOled.putString("*"); 50 | SeeedOled.setTextXY(5,15); 51 | SeeedOled.putString("*"); 52 | SeeedOled.setTextXY(6,0); 53 | SeeedOled.putString("*"); 54 | SeeedOled.setTextXY(6,15); 55 | SeeedOled.putString("*"); 56 | SeeedOled.setTextXY(7,0); 57 | SeeedOled.putString("****************"); 58 | SeeedOled.setTextXY(4,1); 59 | SeeedOled.putString(" Walker "); 60 | 61 | for(int i = 5; i > 0; i--){ 62 | SeeedOled.setTextXY(4,1); //Set the cursor to Xth Page, Yth Column 63 | SeeedOled.putString(" "); 64 | SeeedOled.setTextXY(4,1); //Set the cursor to Xth Page, Yth Column 65 | SeeedOled.putString(" Wait: "); 66 | SeeedOled.setTextXY(4,10); 67 | char number[2]; 68 | SeeedOled.putString(itoa(i,number,10)); //Print the String 69 | delay(1000); 70 | } 71 | SeeedOled.setTextXY(4,1); //Set the cursor to Xth Page, Yth Column 72 | SeeedOled.putString(" "); 73 | SeeedOled.setTextXY(5,1); //Set the cursor to Xth Page, Yth Column 74 | SeeedOled.putString(" "); 75 | SeeedOled.setTextXY(5,1); //Set the cursor to Xth Page, Yth Column 76 | SeeedOled.putString(" STEP:"); 77 | } 78 | 79 | -------------------------------------------------------------------------------- /pedometer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * pedometer.cpp 3 | * use accelerometer to make a pedometer 4 | * 5 | * Copyright (c) 2014 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : lawliet zou 8 | * Create Time: March 2014 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #include "pedometer.h" 34 | 35 | void Pedometer::sensorInit() 36 | { 37 | adxl.powerOn(); 38 | 39 | //set activity/ inactivity thresholds (0-255) 40 | adxl.setActivityThreshold(75); //62.5mg per increment 41 | adxl.setInactivityThreshold(75); //62.5mg per increment 42 | adxl.setTimeInactivity(10); // how many seconds of no activity is inactive? 43 | 44 | //look of activity movement on this axes - 1 == on; 0 == off 45 | adxl.setActivityX(1); 46 | adxl.setActivityY(1); 47 | adxl.setActivityZ(1); 48 | 49 | //look of inactivity movement on this axes - 1 == on; 0 == off 50 | adxl.setInactivityX(1); 51 | adxl.setInactivityY(1); 52 | adxl.setInactivityZ(1); 53 | 54 | //look of tap movement on this axes - 1 == on; 0 == off 55 | adxl.setTapDetectionOnX(0); 56 | adxl.setTapDetectionOnY(0); 57 | adxl.setTapDetectionOnZ(1); 58 | 59 | //set values for what is a tap, and what is a double tap (0-255) 60 | adxl.setTapThreshold(50); //62.5mg per increment 61 | adxl.setTapDuration(15); //625us per increment 62 | adxl.setDoubleTapLatency(80); //1.25ms per increment 63 | adxl.setDoubleTapWindow(200); //1.25ms per increment 64 | 65 | //set values for what is considered freefall (0-255) 66 | adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment 67 | adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment 68 | 69 | //setting all interrupts to take place on int pin 1 70 | //I had issues with int pin 2, was unable to reset it 71 | adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN ); 72 | adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN ); 73 | adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN ); 74 | adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN ); 75 | adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN ); 76 | 77 | //register interrupt actions - 1 == on; 0 == off 78 | adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1); 79 | adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1); 80 | adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1); 81 | adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1); 82 | adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1); 83 | } 84 | 85 | void Pedometer::init() 86 | { 87 | sensorInit(); 88 | stepCount = 0; 89 | updateModelAxis(); 90 | _curr_val = 0; 91 | } 92 | 93 | void Pedometer::updateModelAxis(void) 94 | { 95 | int x,y,z; 96 | int16_t sum[MAX_AXIS] = {0}; 97 | for(int i = 0; i < SAMPLING_MODEL_NUMBER; i++){ 98 | adxl.readXYZ(&x, &y, &z); 99 | sum[X_AXIS] += abs(x); 100 | sum[Y_AXIS] += abs(y); 101 | sum[Z_AXIS] += abs(z); 102 | } 103 | sum[X_AXIS] /= SAMPLING_MODEL_NUMBER; 104 | sum[Y_AXIS] /= SAMPLING_MODEL_NUMBER; 105 | sum[Z_AXIS] /= SAMPLING_MODEL_NUMBER; 106 | _model_axis = sum[X_AXIS] >= sum[Y_AXIS]?X_AXIS:Y_AXIS; 107 | _model_axis = sum[_model_axis] >= sum[Z_AXIS]?_model_axis:Z_AXIS; 108 | _model_val = sum[_model_axis]; 109 | 110 | _model_ratio = (_model_val+MODEL_STANDARD_VALUE/2)/MODEL_STANDARD_VALUE; 111 | } 112 | 113 | void Pedometer::getValue(void) 114 | { 115 | int tmp_val[MAX_AXIS]; 116 | _curr_val = 0; 117 | for(int i = 0; i < MAX_WINDOW; i++){ 118 | adxl.readXYZ(&tmp_val[X_AXIS], &tmp_val[Y_AXIS], &tmp_val[Z_AXIS]); 119 | _curr_val += abs(tmp_val[_model_axis]); 120 | } 121 | _curr_val /= MAX_WINDOW; 122 | 123 | _curr_val = (_curr_val + _model_ratio/2)/_model_ratio; 124 | } 125 | 126 | void Pedometer::getValidValue(void) 127 | { 128 | do{ 129 | getValue(); 130 | }while((abs(_curr_val-_model_val) <= 2) || (_curr_val == _last_val)); 131 | 132 | _last_val = _curr_val; 133 | } 134 | 135 | void Pedometer::stepCalc() 136 | { 137 | unsigned long timerStart,timerEnd; 138 | timerStart = millis(); 139 | timerEnd = 100 + timerStart;//one step is more than 100ms 140 | getValidValue(); 141 | if(_curr_val >= 23){ 142 | while(1){ 143 | getValidValue(); 144 | if(_curr_val <= 17){ 145 | if(millis() > timerEnd) { 146 | stepCount++; 147 | } 148 | break; 149 | } 150 | } 151 | } 152 | } 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /pedometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pedometer.h 3 | * use accelerometer to make a pedometer 4 | * 5 | * Copyright (c) 2014 seeed technology inc. 6 | * Website : www.seeed.cc 7 | * Author : lawliet zou 8 | * Create Time: March 2014 9 | * Change Log : 10 | * 11 | * The MIT License (MIT) 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to deal 15 | * in the Software without restriction, including without limitation the rights 16 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | * copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | * THE SOFTWARE. 30 | */ 31 | 32 | 33 | #include 34 | #include "Arduino.h" 35 | 36 | #define MAX_AXIS 3 37 | #define MAX_WINDOW 3 38 | #define SAMPLING_MODEL_NUMBER 60 39 | #define MODEL_STANDARD_VALUE 20 40 | 41 | enum Axis{ 42 | X_AXIS = 0, 43 | Y_AXIS = 1, 44 | Z_AXIS = 2, 45 | }; 46 | 47 | class Pedometer{ 48 | public: 49 | void init(void); 50 | void stepCalc(void); 51 | uint16_t stepCount; 52 | 53 | private: 54 | void sensorInit(void); 55 | void updateModelAxis(void); 56 | void getValue(void); 57 | void getValidValue(void); 58 | 59 | ADXL345 adxl; 60 | Axis _model_axis; 61 | int _model_val; 62 | int _curr_val; 63 | int _model_ratio; 64 | int _last_val; 65 | }; --------------------------------------------------------------------------------