Relevant software code found online unfiltered and unedited.
Since I am new to Arduino development I’ve gathered the following scripts from various online projects that have some code relevant to the project. I plan on using this code as a template for my own code to streamline the process since while I’m qualified in C++, I have no experience with Arduino. I’ve linked the original pages PLEASE SUPPORT THE ORIGINAL POSTERS
Receive Notification information (Arduino) (source: https://create.arduino.cc/projecthub/geny-studio/notification-iot-using-neopixel-and-smartphone-945e81?ref=user&ref_id=114809&offset=0)
#include <SoftwareSerial.h> #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define PIN 10 #define NUMPIXELS 24 #define rxPin 4 #define txPin 3 SoftwareSerial BT(txPin, rxPin); Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); int delayval = 50; // delay for half a second void setup() { BT.begin(9600); Serial.begin(9600); pixels.begin(); // This initializes the NeoPixel library. } void loop() { if (BT.available() >0) { //Receive values from Notiduino Android App whenever it gets notification messages //Use semicolon and comma as seperator to retrieve header message and RGB color value String BT_receive_data = BT.readStringUntil((char)3); String Message_Head = getValue(BT_receive_data, ';', 0); String ColorValue = getValue(BT_receive_data, ';', 1); int R = getValue(ColorValue, ',', 0).toInt(); int G = getValue(ColorValue, ',', 1).toInt(); int B = getValue(ColorValue, ',', 2).toInt(); Serial.println(Message_Head); Serial.println(ColorValue); for (int i = 0; i<NUMPIXELS; i++) { pixels.setPixelColor(i, pixels.Color(R, G, B)); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. delay(10); pixels.setPixelColor(i, pixels.Color(0, 0, 0)); } } } #pragma region get Value String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++){ if (data.charAt(i) == separator || i == maxIndex){ found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i + 1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } #pragma endregion |
Receive Heartrate information(Arduino)(Source: https://pulsesensor.com/pages/code-and-guide)
|
Display heart rate (Arduino) (Source: http://www.xtronical.com/basics/heart-beat-sensor-ecg-display/)
#define OLED_Address 0x3C Adafruit_SSD1306 oled(1); int x=0; int lastx=0; int lasty=0; int LastTime=0; bool BPMTiming=false; bool BeatComplete=false; int BPM=0; #define UpperThreshold 550 #define LowerThreshold 500 void setup() { oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address); oled.clearDisplay(); oled.setTextSize(2); } void loop() { if(x>127) { oled.clearDisplay(); x=0; lastx=x; } int value=analogRead(0); oled.setTextColor(WHITE); int y=60-(value/16); oled.writeLine(lastx,lasty,x,y,WHITE); lasty=y; lastx=x; // calc bpm if(value>UpperThreshold) { if(BeatComplete) { BPM=millis()-LastTime; BPM=int(60/(float(BPM)/1000)); BPMTiming=false; BeatComplete=false; } if(BPMTiming==false) { LastTime=millis(); BPMTiming=true; } } if((value<LowerThreshold)&(BPMTiming)) BeatComplete=true; // display bpm oled.writeFillRect(0,50,128,16,BLACK); oled.setCursor(0,50); oled.print(BPM); oled.print(" BPM"); oled.display(); x++; } |
Display notifications (Arduino) and Display time (Arduino) (source: https://circuitdigest.com/microcontroller-projects/build-an-arduino-smart-watch-by-interfacing-oled-display-with-android-phone)
#include<SoftwareSerial.h> SoftwareSerial Serial1(10, 11); #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include "Adafruit_SSD1306.h" #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); #define NUMFLAKES 10 #define XPOS 0 #define YPOS 1 #define DELTAY 2 #define LOGO16_GLCD_HEIGHT 16 #define LOGO16_GLCD_WIDTH 16 String str = ""; byte h = 0; byte m = 0; byte S = 0; String dmy, time, network, battery, inNumber, s; byte centerX = 24; byte centerY = 39; byte Radius = 24; double RAD = 3.141592 / 180; double LR = 89.99; void showTimeAnalog(int center_x, int center_y, double pl1, double pl2, double pl3) { double x1, x2, y1, y2; x1 = center_x + (Radius * pl1) * cos((6 * pl3 + LR) * RAD); y1 = center_y + (Radius * pl1) * sin((6 * pl3 + LR) * RAD); x2 = center_x + (Radius * pl2) * cos((6 * pl3 - LR) * RAD); y2 = center_y + (Radius * pl2) * sin((6 * pl3 - LR) * RAD); display.drawLine((int)x1, (int)y1, (int)x2, (int)y2, WHITE); } void digitalClock() { display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(60, 20); display.println(dmy); display.setTextSize(2); display.setCursor(60, 30); display.println(time); display.display(); delay(2000); } |
External Software used(TBD):
- Notiduino APK
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.