自行車騎行監測器,可以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;
0.png (11.92 KB, 下載次數: 88)
下載附件
2017-12-25 23:54 上傳
單片機源程序如下:
- //#include"Arduino.h"
- //#include "AllSerialHanding.h"
- //#include "Interrupt.h"
- //#include "SD_ReadWrite.h"
- #include "all.h"
- #define PROCESSING_VISUALIZER 1
- #define SERIAL_PLOTTER 2
- volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
- volatile int Signal; // holds the incoming raw data
- volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
- static int outputType = SERIAL_PLOTTER;
- String beat_data = " BPM:0 IBI:0 Signal:0";
- void PulseSensor_SD_Write()
- {
- SD_Write("test.txt",beat_data); //脈沖數據寫入SD卡中PulseSensor.txt文件
- }
- // Sends Data to Pulse Sensor Processing App, Native Mac App, or Third-party Serial Readers.
- void sendDataToSerial(char symbol, int data ){
- Serial.print(symbol);
- Serial.println(data);
- }
- void serialOutput(){ // Decide How To Output Serial.
-
- switch(outputType){
- case PROCESSING_VISUALIZER:
- sendDataToSerial('S', Signal); // goes to sendDataToSerial function
- break;
- case SERIAL_PLOTTER: // open the Arduino Serial Plotter to visualize these data
- Serial.print(BPM);
- Serial.print(",");
- Serial.print(IBI);
- Serial.print(",");
- Serial.println(Signal);
- beat_data=" BPM:"+String(BPM)+" IBI:"+String(IBI)+" Signal:"+String(Signal);
-
- break;
- default:
- break;
- }
- }
- // Decides How To OutPut BPM and IBI Data
- void serialOutputWhenBeatHappens(){
- switch(outputType){
- case PROCESSING_VISUALIZER: // find it here https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
- sendDataToSerial('B',BPM); // send heart rate with a 'B' prefix
- sendDataToSerial('Q',IBI); // send time between beats with a 'Q' prefix
- break;
- default:
- break;
- }
- }
- // SET THE SERIAL OUTPUT TYPE TO YOUR NEEDS
- // PROCESSING_VISUALIZER works with Pulse Sensor Processing Visualizer
- // https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
- // SERIAL_PLOTTER outputs sensor data for viewing with the Arduino Serial Plotter
- // run the Serial Plotter at 115200 baud: Tools/Serial Plotter or Command+L
- void ledFadeToBeat(){
- fadeRate -= 15; // set LED fade value
- fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
- analogWrite(fadePin,fadeRate); // fade LED
- }
- void Pulse_Init(){
- pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
- pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
- // Serial.begin(115200); // we agree to talk fast!
- interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
- // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
- // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
- // analogReference(EXTERNAL);
- }
- // Where the Magic Happens
- void Pulse_Allot(){
- serialOutput() ;
- if (QS == true){ // A Heartbeat Was Found
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
自行車騎行監測器.zip
(11.53 KB, 下載次數: 10)
2017-12-24 15:18 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|