找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3532|回复: 0
打印 上一主题 下一主题
收起左侧

MEGA2560主控自行车骑行监测器源码

[复制链接]
跳转到指定楼层
楼主
自行车骑行监测器,可以GPS定位,检测骑行速度,检测心率,同时将以上数据写入SD卡内进行保存,使用MEGA2560主控
SD卡的SPI接口 ** MOSI - pin 51 ** MISO - pin 50 ** CLK  - pin 52 ** CS   - pin 53

GPS的串口使用mega2560的串口1  Serial 1: Pin19 (RX) and Pin18 (TX);Pin13接一个LED显示GPS是否工作正常

两个霍尔传感器接在外部中断  Pin2 (interrupt 0), Pin3 (interrupt 1)

心跳指示灯在 Pin5   int fadePin = 5
int blinkPin = 14;               


单片机源程序如下:
  1. //#include"Arduino.h"
  2. //#include "AllSerialHanding.h"
  3. //#include "Interrupt.h"
  4. //#include "SD_ReadWrite.h"
  5. #include "all.h"
  6. #define PROCESSING_VISUALIZER 1
  7. #define SERIAL_PLOTTER  2
  8. volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
  9. volatile int Signal;                // holds the incoming raw data
  10. volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded!
  11. static int outputType = SERIAL_PLOTTER;
  12. String beat_data = " BPM:0 IBI:0 Signal:0";

  13. void PulseSensor_SD_Write()
  14. {
  15.   SD_Write("test.txt",beat_data);  //脉冲数据写入SD卡中PulseSensor.txt文件
  16. }
  17. //  Sends Data to Pulse Sensor Processing App, Native Mac App, or Third-party Serial Readers.
  18. void sendDataToSerial(char symbol, int data ){
  19.     Serial.print(symbol);
  20.     Serial.println(data);
  21.   }
  22. void serialOutput(){   // Decide How To Output Serial.
  23.   
  24.   switch(outputType){
  25.     case PROCESSING_VISUALIZER:
  26.       sendDataToSerial('S', Signal);     // goes to sendDataToSerial function
  27.       break;
  28.     case SERIAL_PLOTTER:  // open the Arduino Serial Plotter to visualize these data
  29.       Serial.print(BPM);
  30.       Serial.print(",");
  31.       Serial.print(IBI);
  32.       Serial.print(",");
  33.       Serial.println(Signal);
  34.       beat_data=" BPM:"+String(BPM)+" IBI:"+String(IBI)+" Signal:"+String(Signal);
  35.       
  36.       break;
  37.     default:
  38.       break;
  39.   }

  40. }

  41. //  Decides How To OutPut BPM and IBI Data
  42. void serialOutputWhenBeatHappens(){
  43.   switch(outputType){
  44.     case PROCESSING_VISUALIZER:    // find it here https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
  45.       sendDataToSerial('B',BPM);   // send heart rate with a 'B' prefix
  46.       sendDataToSerial('Q',IBI);   // send time between beats with a 'Q' prefix
  47.       break;

  48.     default:
  49.       break;
  50.   }
  51. }

  52. // SET THE SERIAL OUTPUT TYPE TO YOUR NEEDS
  53. // PROCESSING_VISUALIZER works with Pulse Sensor Processing Visualizer
  54. //      https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
  55. // SERIAL_PLOTTER outputs sensor data for viewing with the Arduino Serial Plotter
  56. //      run the Serial Plotter at 115200 baud: Tools/Serial Plotter or Command+L

  57. void ledFadeToBeat(){
  58.     fadeRate -= 15;                         //  set LED fade value
  59.     fadeRate = constrain(fadeRate,0,255);   //  keep LED fade value from going into negative numbers!
  60.     analogWrite(fadePin,fadeRate);          //  fade LED
  61.   }

  62. void Pulse_Init(){
  63.   pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
  64.   pinMode(fadePin,OUTPUT);          // pin that will fade to your heartbeat!
  65. //  Serial.begin(115200);             // we agree to talk fast!
  66.   interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS
  67.    // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
  68.    // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
  69. //   analogReference(EXTERNAL);
  70. }


  71. //  Where the Magic Happens
  72. void Pulse_Allot(){

  73.     serialOutput() ;

  74.   if (QS == true){     // A Heartbeat Was Found
  75. ……………………

  76. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
自行车骑行监测器.zip (11.53 KB, 下载次数: 10)





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表