找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3092|回复: 1
收起左侧

Arduino+puleseSensor+OLED心率监测装置源码

[复制链接]
ID:310193 发表于 2018-7-7 19:21 | 显示全部楼层 |阅读模式
课程报告时顺便做的一个小玩意
0.png
单片机源程序如下:
  1. int pulsePin = A0;                 // Pulse Sensor purple wire connected to analog pin 0
  2. int blinkPin = 12;                // pin to blink led at each beat
  3. int fadePin = 13;                  // pin to do fancy classy fading blink at each beat
  4. int fadeRate = 0;                 // used to fade LED on with PWM on fadePin
  5. // these variables are volatile because they are used during the interrupt service routine!
  6. volatile int BPM;                   // used to hold the pulse rate
  7. volatile int Signal;                // holds the incoming raw data
  8. volatile int IBI = 600;             // holds the time between beats, must be seeded!
  9. volatile boolean Pulse = false;     // true when pulse wave is high, false when it's low
  10. volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

  11. #include "U8glib.h"
  12. U8GLIB_SSD1306_128X64 u8g(5, 4, 6, 2, 3);  // SW SPI Com: SCL = 5,SDA = 4,CS = 6,RST = 3,DC = 2
  13. const uint8_t rook_bitmap[] PROGMEM = {

  14.   0x00,         // 00000000
  15.   0x55,         // 01010101
  16.   0x7f,          // 01111111
  17.   0x3e,         // 00111110
  18.   0x3e,         // 00111110
  19.   0x3e,         // 00111110
  20.   0x3e,         // 00111110
  21.   0x7f           // 01111111
  22. };
  23. void setup() {
  24.   pinMode(blinkPin, OUTPUT);        // pin that will blink to your heartbeat!
  25.   pinMode(fadePin, OUTPUT);         // pin that will fade to your heartbeat!
  26.   Serial.begin(115200);             // we agree to talk fast!
  27.   interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS
  28.   // UN-COMMENT THE NEXT LINE IF YOU ARE POWERING The Pulse Sensor AT LOW VOLTAGE,
  29.   // AND APPLY THAT VOLTAGE TO THE A-REF PIN
  30.   //analogReference(EXTERNAL);
  31.   u8g.setColorIndex(1);         // pixel on
  32. }

  33. void loop() {
  34.   u8g.firstPage();
  35.   do {
  36.     draw();
  37.   } while ( u8g.nextPage() );
  38.   sendDataToProcessing(' ', Signal);     // send Processing the raw Pulse Sensor data
  39.   if (QS == true) {                      // Quantified Self flag is true when arduino finds a heartbeat
  40.     fadeRate = 255;                  // Set 'fadeRate' Variable to 255 to fade LED with pulse
  41.     sendDataToProcessing(',', BPM);  // send heart rate with a 'B' prefix
  42.     sendDataToProcessing(',', IBI);  // send time between beats with a 'Q' prefix
  43.     QS = false;                      // reset the Quantified Self flag for next time
  44.   }
  45.   ledFadeToBeat();
  46.   delay(20);                             //  take a break
  47. }

  48. void draw(void) {
  49.   // graphic commands to redraw the complete screen should be placed here
  50.   u8g.setFont(u8g_font_fur20);
  51.   //u8g.setFont(u8g_font_osb21);
  52.   if (QS) {
  53.     u8g.drawBitmapP( 40, 40, 1, 8, rook_bitmap);
  54.   }
  55.   u8g.drawStr( 10, 20, "BPM");
  56.   u8g.setPrintPos(80, 20);
  57.   u8g.print(BPM);
  58. }
  59. void ledFadeToBeat() {
  60.   fadeRate -= 15;                         //  set LED fade value
  61.   fadeRate = constrain(fadeRate, 0, 255); //  keep LED fade value from going into negative numbers!
  62.   analogWrite(fadePin, fadeRate);         //  fade LED
  63. }


  64. void sendDataToProcessing(char symbol, int data ) {
  65.   Serial.print(symbol);                // symbol prefix tells Processing what type of data is coming
  66.   Serial.println(data);                // the data to send culminating in a carriage return
  67. }
复制代码

所有资料51hei提供下载:
pulseOLED.zip (3.48 KB, 下载次数: 31)
回复

使用道具 举报

ID:208271 发表于 2023-2-22 23:08 | 显示全部楼层
没有#include "U8glib.h",无法使用
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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