The Accelerometer CSE 391 Fall 2011 Tony Scarlatos.

Slides:



Advertisements
Similar presentations
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Advertisements

Slide 1 of 7 Turning off Ad-Hoc Mode Ad-Hoc mode can be a real problem for wireless connectivity at meetings. Systems that accidentally enter.
Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012.
IOS and AddressBook CS4521. Address Book UI Framework Exploring Contacts.
The First Program. Step 1  File->New Project Create a project named “HelloWorld”, and select View Based Application from the icons on the right.
Other Input Methods Pre-Lab Lecture 4 1. Revisit 2  Pre-Lab 3 – Animation  Boundary Information  Layer Concept  Animation algorithm  Next Position.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Friday, August 29, 2014 CSCI 351 – Mobile Applications Development.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Printing and Page Formatting ITSW 1401, Intro to Word Processing Instructor: Glenda H. Easter.
Adobe Forms THE FORM ELEMENT PANEL. Creating a form using the Adobe FormsCentral is a quick and easy way to distribute a variety of forms including surveys.
Getting Started with Adobe Dreamweaver CS6. Unit Objectives Define web design software Start Adobe Dreamweaver CS6 View the Dreamweaver workspace Work.
Sprite Animation CSE 391 Fall 2012 Tony Scarlatos.
IOS WorkShoP Xcode 4 iOS 5 : “A Primer”. Objective-C iOS applications are written in Objective-C language using the Cocoa Touch library Objective-C is.
Simple Game Animation – iPhone Programming Exercise 3 CSE 391 Fall 2012 Tony Scarlatos.
Xcode testing Using XCTest.
Chapter 10: Move! Creating Animation
Intro to the Xcode IDE and the iOS SDK CSE 391 Fall 2012 Tony Scarlatos.
Introduction to Mobile Programming. Slide 2 Overview Fundamentally, it all works the same way You get the SDK for the device (Droid, Windows, Apple) You.
Technology Planning & ePeGS David W. Dillard David W. Dillard Arcadia Valley R-II.
Introduction to Maya. Maya’s Layout User Interface Elements In Maya, you can tear off menus to create separate floating boxes that you can place anywhere.
iOS components in Swift
1 Designing with a UIToolBar iPhone/iPad, iOS Development Tutorial.
Wii mote interfacing. The product It is a wireless device, using standard Bluetooth technology to communicate The Wii Remote uses the standard Bluetooth.
QAD Reporting Framework Stacy Green, BravePoint MWUG Mar 2013.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
Navigation in iPads splitViewController. Overview Create a Master-Detail application Switch Device Family to iPad Give the project a name and click “Use.
IOS with Swift Hello world app.
Using Xcode A Beginner’s Tutorial Erin Green. This tutorial will walk you through Xcode, a software development tool for Apple’s iOS applications – We.
Create a Web View App Step-by-Step. Step 1 Create a new project in XCode using the "Single View Application" option.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Orientation Configuration adapting to orientation changes.
Chapter 9 Advanced Assembly Modeling Techniques. After completing this chapter, you will be able to perform the following: –Create design view representations.
IMovie 10 Overview. Importing Files from a Video Camera into iMovie 1.Plug the camera into a wall outlet using the power supply. (Some cameras will not.
Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software
The Controller in MVC of iOS CS4521. The controller in the MVC  Controller  Knows about model and view objects  The brains of the operation  Manages.
1 UI Alert View iPhone/iPad, iOS Development Tutorial.
Lecture 10 Using Interface Builder to create Mac Applications.
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
Key Applications Module Lesson 22 — Managing and Reporting Database Information Computer Literacy BASICS.
Folio3 IPhone Training Session 2 Testing App on device Presenter: Imam Raza.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
Accelerometer based motion gestures for mobile devices Presented by – Neel Parikh Advisor Committee members Dr. Chris Pollett Dr. Robert Chun Dr. Mark.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
1 디바이스 정보  UIDevice 클래스가 제공하고 static 메서드인 currentDevice 가 객체를 생성합 니다.  제공하는 정보 uniqueIdentifier: 장치 고유 ID / 회원가입을 하지 않고 어플을 운영 가능 model: 모델명 systemVersion:
CHAPTER 8 Sensors and Camera. Chapter objectives: Understand Motion Sensors, Environmental Sensors and Positional Sensors Learn how to acquire measurement.
Chapter 9 Advanced Assembly Modeling Techniques. After completing this chapter, you will be able to perform the following: –Create design view representations.
Mind Mapping with Bubbl.us. The Bubbl.us Homepage Click to create a bubbl.us account Sign in or, To access, type
 Motion Tween allow us to move a shape on the stage from one place to another.  In order to use motion tween, the shape to be moved must be converted.
Outline  What is MySmartEye ?  Motivation, objectives.  Implementation.  Programming techniques.  Future Work.  Demo.
Iphone Online Training AcuteSoft: India: , Land Line: +91 (0) USA: , UK : +44.
iOS UI Components Sisoft Technologies Pvt Ltd
Designing with Introspection
T_C_N_L_G_ E D I D I E O Y O H I E B J I R E A A W.
CSCI 351 – Mobile Applications Development
Introduction to Computers
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
CSC 581: Mobile App Development
EEC-492/693/793 iPhone Application Development
CSC 581: Mobile App Development
Android Topics Sensors Accelerometer and the Coordinate System
ICT Spreadsheets Lesson 1: Introduction to Spreadsheets
Apple Xcode with Swift Demo
EEC-492/693/793 iPhone Application Development
Presentation transcript:

The Accelerometer CSE 391 Fall 2011 Tony Scarlatos

The Three Axes on the iPhone

Example Values: Portrait Y = (gravity) Z = 0.0 X = 0.0

Example Values: Landscape Right Y = 0.0Z = 0.0 X = 1.0 (negative if landscape left)

Example Values: Tilt 45 degrees X & Y Y = Z = 0.0 X = 0.5

Example Values: Tilt 45 degrees Y & Z Y = Z = X = 0.0

Uses for accelerometer values Detect orientation change – Ex. Portrait to Landscape Detect a “Shake” – Often used to clear fields or undo an action Use the Accelerometer as a control – Commonly used in games

Detecting and Managing Orientation If you want your interface to adapt to different orientations, such as rotating from portrait to landscape, you’ll have to edit the shouldAutorotateToInterfaceOrientation method in your view controller to be specific about which orientations you want to support. In the code that follows on the next slide, the supported orientations are Portrait, LandscapeLeft and LandscapeRight. In the simulator you can change orientations from the Hardware drop down menu.

The shouldAutorotateToInterfaceOrientation method // Override to allow orientations other than the default portrait orientation. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrien tation { // Return YES for supported orientations if (interfaceOrientation == UIInterfaceOrientationPortrait || //two vertical lines denote an OR statement interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES; else { return NO; }

Locking out an orientation It seems like this is a good place to remind you of the code we used to force the app into landscape mode in an earlier demo: -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPort raitUpsideDown)) // NO locks out the portrait mode of the iPhone. The initial landscape orientation is also set in the summary panel for the app target. { return NO; } if ((interfaceOrientation==UIInterfaceOrientationLandscapeLeft)||(interfaceOrientation==UIInterfaceOrientat ionLandscapeRight)) { return YES; }

Interface Builder Autosizing Panel If you want to compensate for the changes to your interface because of supporting multiple orientations, you can select those UI elements in IB, and in the Autosizing tab of the Inspector panel you can adjust their properties. You can choose which sides of the frame you want anchor the element to (struts), or if you want the element to stretch to fit the new orientation (springs).

Interface Builder Autosizing Panel STRUTS connect The UI element to the sides of the view (upper left corner is the default) SPRINGS stretch The UI element to the sides of the view The preview window shows the effects of your changes to the UI element Origin establishes the location of the element in the view Fields for entering discrete values for size and position of the UI element

Detecting a Motion Event (Shake) The first thing to do to detect a motion event is to declare that the view controller can be the first responder. The next thing to do is activate that status using the viewDidAppear method. Then you can respond to either the motionBegan or motionEnded methods (or both). You can test the event in the simulator in the Hardware drop down menu which simulates a shake event. The code is written in the implementation file of the view controller, and it simply changes the background color of the view when the phone is shaken. It follows on the next slide.

The Shake Event -(BOOL)canBecomeFirstResponder { return YES; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self becomeFirstResponder]; } -(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.subtype == UIEventSubtypeMotionShake) { self.view.backgroundColor = [UIColor redColor]; }

Accessing Accelerometer data The UIAccelerometer object contains the combined data from the 3 sensors (axes) on the iPhone. It is a “singleton” object – it always exists. You don’t have to create or release it, you just need to request it. The method used to access the data is sharedAccelerometer. Typically you set the delegate of the object to your view controller (self). The other thing that you will need to set is the sampling rate using the updateInterval method. A typical sampling rate is 30 times per second. You can then use the data in your app by employing the didAccelerate method. In the code that follows on the next 3 slides we set up a View-based Application that displays accelerometer data in three labels and three progress bars.

The mainViewController.h MainViewController : UIViewController { IBOutlet UILabel *labelX; IBOutlet UILabel *labelY; IBOutlet UILabel *labelZ; IBOutlet UIProgressView *progressX; IBOutlet UIProgressView *progressY; IBOutlet UIProgressView *progressZ; UIAccelerometer *accelerometer; (nonatomic, retain) IBOutlet UILabel (nonatomic, retain) IBOutlet UILabel (nonatomic, retain) IBOutlet UILabel (nonatomic, retain) IBOutlet UIProgressView (nonatomic, retain) IBOutlet UIProgressView (nonatomic, retain) IBOutlet UIProgressView (nonatomic, retain) UIAccelerometer *accelerometer;

The mainViewController.m file accelerometer;

The mainViewController.m file (2) -(void)viewDidLoad { [super viewDidLoad]; self.accelerometer = [UIAccelerometer sharedAccelerometer]; self.accelerometer.updateInterval =.1; self.accelerometer.delegate = self; } -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { labelX.text = ", acceleration.x]; labelY.text = ", acceleration.y]; labelZ.text = ", acceleration.z]; self.progressX.progress = ABS(acceleration.x); self.progressY.progress = ABS(acceleration.y); self.progressZ.progress = ABS(acceleration.z); }

Testing the accelerometer app The iPhone simulator does not natively support data from the accelerometer, but there are a couple of plug-ins for Xcode that allow your device to send that information to the simulator wirelessly. The free app, AccSim, is available on the App Store. The files it depends upon (which have to be added to your Xcode project) are available at: A more robust app that also shares location and touch event data with the simluator is iSimulate. It’s available on the App Store for $ It has a library which has to be embedded in your Xcode project that is available here: The advantage of both of these apps is that you don’t have to install your project on your device to be able to test your code. They also provide a convenient way to make video trailers of your apps that use accelerometer input, like games.