PTSD PAL
I chose this project because I am very familiar with the affect of PTSD and what it does to veterans and wanted to try to find a solution that when having a ptsd attack at night it will send some noise or vibration to wake you up. As many of my friends are veterans and active duty soldiers that have suffered from severe PTSD attacks at night and have not only accidentally hurt themselves but others as well if not woken up properly, I created this in an attempt to make their lives easier.
Supplies
Apple Watch or Iphone
Laptop
code.org account
on code.org create your account
Go to app lab
Add the first screen and text box
Add the textbox on screen one to the code
After that, insert the following code.
Then hit new screen on the design menu and create screen two
repeat step three and four and six
Then prep your code and insert the following code.
hideElement("introlabel");
setScreen("screen2");
onEvent("HelpLabel", "click", function( ) {
console.log("HelpLabel clicked!");
setScreen("screen4");
onEvent("SetUp", "click", function( ) {
open("https://onlineheartbeat.com");
import HealthKit drawChartFromRecords();
class HeartRateTracker {
let healthStore HKHealthStore();
func requestAuthorization() {
let typesToRead: Set<HKObjectType> = [HKObjectType.quantityType(forIdentifier: .heartRate)!]
healthStore.requestAuthorization(toShare: nil, read: typesToRead) { (success, error) in
if success {
print("HealthKit authorization granted.")
self.startTrackingHeartRate()
} else {
print("HealthKit authorization denied.")
}
}
}
func startTrackingHeartRate() {
guard HKHealthStore.isHealthDataAvailable() else {
print("Health data is not available on this device.")
return
}
let heartRateType = HKQuantityType.quantityType(forIdentifier: .heartRate)!
let query = HKObserverQuery(sampleType: heartRateType, predicate: nil) { (query, completionHandler, error) in
if let error = error {
print("Error observing heart rate changes: \(error.localizedDescription)")
return
}
// Handle heart rate changes here
self.fetchLatestHeartRate()
completionHandler()
}
healthStore.execute(query)
healthStore.enableBackgroundDelivery(for: heartRateType, frequency: .immediate) { (success, error) in
if success {
print("Background delivery enabled for heart rate changes.")
} else {
print("Error enabling background delivery: \(error?.localizedDescription ?? "")")
}
}
}
func fetchLatestHeartRate() {
let heartRateType = HKQuantityType.quantityType(forIdentifier: .heartRate)!
let query = HKSampleQuery(sampleType: heartRateType, predicate: nil, limit: 1, sortDescriptors: nil) { (query, samples, error) in
if let error = error {
print("Error fetching heart rate samples: \(error.localizedDescription)")
return
}
guard let heartRateSample = samples?.first as? HKQuantitySample else {
print("No heart rate data available.")
return
}
let heartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute())
let heartRateValue = heartRateSample.quantity.doubleValue(for: heartRateUnit)
print("Latest Heart Rate: \(heartRateValue) bpm")
}
healthStore.execute(query)
}
}
// Example usage:
let heartRateTracker = HeartRateTracker()
heartRateTracker.requestAuthorization()
create the button that starts sending you to the health app
once you finish the code connect to iPhone or Apple Watch and you're set