iPhone vibration app: I have never coded an... - Cure Parkinson's

Cure Parkinson's

26,958 members28,377 posts

iPhone vibration app

Triever7 profile image
16 Replies

I have never coded an app, but I just got Chat GPT 4 to write the code for a very basic iPhone vibration app. I can’t help anyone, other than to share the code, but I thought I would let people know it’s possible. Looks like it could be customizable too.

Written by
Triever7 profile image
Triever7
To view profiles and participate in discussions please or .
16 Replies
CuriousMe12 profile image
CuriousMe12

Pretty much what cue1 does

Gioc profile image
Gioc

simple and effective, Triever7

Here is a study on the subject:

pmc.ncbi.nlm.nih.gov/articl...

Fed1000

Italian Prealps today
Fed1000 profile image
Fed1000 in reply toGioc

Thanks for information. It's a very interesting study and I don't think I'm much mistaken when I say that Carl Beech took inspiration from here to create his Beech Band. Merry Christmas

Boscoejean profile image
Boscoejean

with regard to the Emma watch which has been researched I am trying to find out if it will be made available anytime in the foreseeable future

mashable.com/article/micros...

alaynedellow profile image
alaynedellow

research CUE in uk

Boscoejean profile image
Boscoejean in reply toalaynedellow

Cue not offered in US

CuriousMe12 profile image
CuriousMe12 in reply toalaynedellow

£800 !

india245 profile image
india245

how brilliant. Could you send me the code please, or tell me what you typed into chat GPT so I can do it for myself?

I wonder if this is similar to the beech band which I am waiting for. I found the cue to be too overstimulating for me

Pixelpixie profile image
Pixelpixie

can you share code?

Triever7 profile image
Triever7

this is the code. Deployment iOS 18.2 or later. Still buggy - does not run in the background and I have to close out and reopen to get it to start again. I have not integrated Apple Watch.

import SwiftUI

import CoreHaptics

struct ContentView: View {

@State private var engine: CHHapticEngine?

@State private var frequency: Double = 150.0 // Hz

@State private var intensity: Double = 0.5 // 0.0 to 1.0

@State private var duration: Double = 1.0 // Seconds

@State private var isPlaying = false

var body: some View {

VStack(spacing: 20) {

Text("Vibration Control")

.font(.largeTitle)

.bold()

// Frequency Slider

VStack {

Text("Frequency: \(Int(frequency)) Hz")

Slider(value: $frequency, in: 1...300, step: 1)

}

// Intensity Slider

VStack {

Text("Intensity: \(String(format: "%.2f", intensity))")

Slider(value: $intensity, in: 0.0...1.0, step: 0.01)

}

// Duration Slider

VStack {

Text("Duration: \(String(format: "%.2f", duration)) seconds")

Slider(value: $duration, in: 0.1...10.0, step: 0.1)

}

// Play/Stop Button

Button(action: toggleHaptic) {

Text(isPlaying ? "Stop Vibration" : "Start Vibration")

.font(.headline)

.padding()

.frame(maxWidth: .infinity)

.background(isPlaying ? Color.red : Color.green)

.foregroundColor(.white)

.cornerRadius(10)

}

}

.padding()

.onAppear(perform: prepareHaptics)

}

func prepareHaptics() {

guard CHHapticEngine.capabilitiesForHardware().supportsHaptics else {

print("Haptics not supported on this device.")

return

}

do {

engine = try CHHapticEngine()

try engine?.start()

} catch {

print("Failed to start haptic engine: \(error.localizedDescription)")

}

}

func playHaptic() {

guard let engine = engine else { return }

do {

let intensityParameter = CHHapticEventParameter(parameterID: .hapticIntensity, value: Float(intensity))

let sharpnessParameter = CHHapticEventParameter(parameterID: .hapticSharpness, value: 0.5)

let event = CHHapticEvent(

eventType: .hapticContinuous,

parameters: [intensityParameter, sharpnessParameter],

relativeTime: 0,

duration: duration

)

let pattern = try CHHapticPattern(events: [event], parameters: [])

let player = try engine.makePlayer(with: pattern)

try player.start(atTime: 0)

} catch {

print("Failed to play haptic: \(error.localizedDescription)")

}

}

func toggleHaptic() {

if isPlaying {

engine?.stop(completionHandler: nil)

isPlaying = false

} else {

playHaptic()

isPlaying = true

}

}

}

@main

struct VibrationControlApp: App {

var body: some Scene {

WindowGroup {

ContentView()

}

}

}

Triever7 profile image
Triever7

I prompted it by asking it about the Beech Band and Tass gloves and asking if it could code an app that met these specifications. Its not perfect, but it runs. Happy to take friendly amendments. I am no expert at this, though I see the logic of it. I write code for data analysis.

Southernbird profile image
Southernbird

what does the vibration app control? Is it compatible with the apple watch?

Triever7 profile image
Triever7

it controls the phone, which allows custom haptics. It can be integrated with the watch but I haven’t tried. I’ve been using a haptic metronome app for that. It’s called Haptik, but there are many. Really just kind of nodding around waiting for products to actually arrive

MellowYellowcup profile image
MellowYellowcup

thanks heaps

Shack2023 profile image
Shack2023

hi Triver! Where does the code go to create the IPhone app? Is there a developer app where the code can be copy pasted to? Thank you in advance !!!!

Triever7 profile image
Triever7

the program is called Xcode. If you paste all that code into chat gpt and ask for step by step installation instructions, you should get them. Remember, this is iPhone running on iOS 18.2 . Other than that, I have no expertise.

Not what you're looking for?

You may also like...

Tass-style Glove iPhone App + Hardware

Hi folks, Starting a new thread here . A few of us have been iterating on a solution using the...
DanTeoh profile image

Yuka app

Welcome to Yuka, the 100% independent app that will help you choose the best products for your...
MarionP profile image

Lean app

Poor posture has been a large part of my Parkinson's experience. In fact, I've had poor posture...
johntPM profile image

Beats Medical - Metronome app

Just posted a video demonstrating the @BeatsMedical metronome app designed for PwP's....

Tap Test App

If you're like me, you'll want to measure your Parkinson's symptoms. As part of that, I've written...
johntPM profile image

Moderation team

See all
CPT_Aleksandra profile image
CPT_AleksandraAdministrator
CPT_Anaya profile image
CPT_AnayaAdministrator

Content on HealthUnlocked does not replace the relationship between you and doctors or other healthcare professionals nor the advice you receive from them.

Never delay seeking advice or dialling emergency services because of something that you have read on HealthUnlocked.