Post

Replies

Boosts

Views

Activity

How di
Hi. I have been trying to figure out the code for this program for weeks now and can't figure it out. I apologize for the repeated postings. I have the following code. I am trying to find distance and velocity in the following program. I keep getting error messages. Any help would be very much appreciated! Thank you! import UIKit import CoreMotion let motion = CMMotionManager() class ViewController: UIViewController { @IBOutlet var xaxis: UILabel! @IBOutlet var yaxis: UILabel! @IBOutlet var zaxis: UILabel! let movementManager = CMMotionManager() override func viewDidLoad() { super.viewDidLoad() movementManager.startAccelerometerUpdates() movementManager.accelerometerUpdateInterval = 0.1 if let data = self.movementManager.accelerometerData { self.xaxis.text = String(data.acceleration.x) //OLD - self.yaxis.text = String(data.acceleration.y) //OLD - self.zaxis.text = String(data.acceleration.z) var xoutput = self.xaxis.text var distance: Double = 0.0 var velocityi: Double = 0.0 var velocityf: Double = 0.0 var x: Int = 1 while x == 1 { distance = velocityi * 0.1 + (1/2) * xoutput * pow(0.1, 2) velocityf = velocityi + xoutput * 0.1 velocityi = velocityf } } } }
4
0
200
Sep ’25
Output is stuck on String
Hi. I have the following code with results in an error message // // ViewController.swift // Accelerometer // // import UIKit import CoreMotion let motion = CMMotionManager() class ViewController: UIViewController { @IBOutlet var xaxis: UILabel! @IBOutlet var yaxis: UILabel! @IBOutlet var zaxis: UILabel! let movementManager = CMMotionManager() override func viewDidLoad() { super.viewDidLoad() movementManager.startAccelerometerUpdates() movementManager.accelerometerUpdateInterval = 0.1 Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { _ in if let data = self.movementManager.accelerometerData { // self.xaxis.text = String(data.acceleration.x) //self.yaxis.text = String(data.acceleration.y) //self.zaxis.text = String(data.acceleration.z) var xoutput: () = self.xaxis.text = String(data.acceleration.x) var xoutput = xoutput * 9.81 print(xoutput) } } } } I realize that it is not working since the whole value of "xoutput" has a string in it. Any advice on making it so it will be a Double? THANK YOU!
1
0
117
Aug ’25
Xcode won't execute code?
Hi everyone. I have the following code that I am trying to execute in Xcode. I then install it on my iPhone. It doesn't run at all and I don't know why. Any thoughts? Thank you. import CoreMotion class MyViewController: UIViewController { let motionManager = CMMotionManager() func startAccelerometer() { if motionManager.isAccelerometerAvailable { motionManager.accelerometerUpdateInterval = 0.1 // 10 updates per second motionManager.startAccelerometerUpdates(to: .main) { (data, error) in guard let accelerometerData = data else { return } let x = accelerometerData.acceleration.x let y = accelerometerData.acceleration.y let z = accelerometerData.acceleration.z // Process the x, y, and z acceleration values here print("X: \(x), Y: \(y), Z: \(z)") } } } }
7
0
191
Aug ’25
How can I calculate distance and vertical velocity?
Can't I just add up all of the accelerations of the accelerometer and then use this physics equation to get distance? d = v(i) x t + (1/2) x a x t ^2 In this: v(i) would be 0 t = 1 second a = all accelerometer speeds added together for.1 second t = 1 second Can't I just use this equation to get vertical velocity? A lot of people have said it is impossible but It has been done with variometer apps. I can’t figure out the code. Can anyone guide me in the right direction? v(f) = v(i) + a x t v(i) = 0 a = y-axis acceleration for 1 second t = 1 second Please let me know if this is possible. Thank you so much for your help.
2
0
205
Aug ’25
How di
Hi. I have been trying to figure out the code for this program for weeks now and can't figure it out. I apologize for the repeated postings. I have the following code. I am trying to find distance and velocity in the following program. I keep getting error messages. Any help would be very much appreciated! Thank you! import UIKit import CoreMotion let motion = CMMotionManager() class ViewController: UIViewController { @IBOutlet var xaxis: UILabel! @IBOutlet var yaxis: UILabel! @IBOutlet var zaxis: UILabel! let movementManager = CMMotionManager() override func viewDidLoad() { super.viewDidLoad() movementManager.startAccelerometerUpdates() movementManager.accelerometerUpdateInterval = 0.1 if let data = self.movementManager.accelerometerData { self.xaxis.text = String(data.acceleration.x) //OLD - self.yaxis.text = String(data.acceleration.y) //OLD - self.zaxis.text = String(data.acceleration.z) var xoutput = self.xaxis.text var distance: Double = 0.0 var velocityi: Double = 0.0 var velocityf: Double = 0.0 var x: Int = 1 while x == 1 { distance = velocityi * 0.1 + (1/2) * xoutput * pow(0.1, 2) velocityf = velocityi + xoutput * 0.1 velocityi = velocityf } } } }
Replies
4
Boosts
0
Views
200
Activity
Sep ’25
Output is stuck on String
Hi. I have the following code with results in an error message // // ViewController.swift // Accelerometer // // import UIKit import CoreMotion let motion = CMMotionManager() class ViewController: UIViewController { @IBOutlet var xaxis: UILabel! @IBOutlet var yaxis: UILabel! @IBOutlet var zaxis: UILabel! let movementManager = CMMotionManager() override func viewDidLoad() { super.viewDidLoad() movementManager.startAccelerometerUpdates() movementManager.accelerometerUpdateInterval = 0.1 Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { _ in if let data = self.movementManager.accelerometerData { // self.xaxis.text = String(data.acceleration.x) //self.yaxis.text = String(data.acceleration.y) //self.zaxis.text = String(data.acceleration.z) var xoutput: () = self.xaxis.text = String(data.acceleration.x) var xoutput = xoutput * 9.81 print(xoutput) } } } } I realize that it is not working since the whole value of "xoutput" has a string in it. Any advice on making it so it will be a Double? THANK YOU!
Replies
1
Boosts
0
Views
117
Activity
Aug ’25
Accelerometer data not printing correctly.
Hi everyone. I am trying to place accelerometer data on my iPhone App. However, when printing the data, the data is on top of each other and sometimes at the top of the screen. Labels are also abbreviated. I am clueless. I would appreciate any help. Below are photos. Thank you!!
Replies
1
Boosts
0
Views
146
Activity
Aug ’25
Xcode won't execute code?
Hi everyone. I have the following code that I am trying to execute in Xcode. I then install it on my iPhone. It doesn't run at all and I don't know why. Any thoughts? Thank you. import CoreMotion class MyViewController: UIViewController { let motionManager = CMMotionManager() func startAccelerometer() { if motionManager.isAccelerometerAvailable { motionManager.accelerometerUpdateInterval = 0.1 // 10 updates per second motionManager.startAccelerometerUpdates(to: .main) { (data, error) in guard let accelerometerData = data else { return } let x = accelerometerData.acceleration.x let y = accelerometerData.acceleration.y let z = accelerometerData.acceleration.z // Process the x, y, and z acceleration values here print("X: \(x), Y: \(y), Z: \(z)") } } } }
Replies
7
Boosts
0
Views
191
Activity
Aug ’25
How can I calculate distance and vertical velocity?
Can't I just add up all of the accelerations of the accelerometer and then use this physics equation to get distance? d = v(i) x t + (1/2) x a x t ^2 In this: v(i) would be 0 t = 1 second a = all accelerometer speeds added together for.1 second t = 1 second Can't I just use this equation to get vertical velocity? A lot of people have said it is impossible but It has been done with variometer apps. I can’t figure out the code. Can anyone guide me in the right direction? v(f) = v(i) + a x t v(i) = 0 a = y-axis acceleration for 1 second t = 1 second Please let me know if this is possible. Thank you so much for your help.
Replies
2
Boosts
0
Views
205
Activity
Aug ’25