Screen Time Monitor
Mobile phones are hard to put down. It’s easy to become distracted when texting with your friends, browsing social media or playing games. You can use your Light Phidget to help keep you on task when you are studying or in class. In this project, you will create a Phone screen time monitor. It will keep track of the time spent with your phone, helping you spend less time on your phone!

Setup
Before getting started, make sure you have the following parts.
VINT Hub

Cellphone

Write code (Java)
Copy the code below into a new Java project. If you need a reminder of how to do this, revisit the Getting Started Course. Insert the code below.
Not your programming language? Set your preferences so we can display relevant code examples
Write code (Python)
Copy the code below into a new Python project. If you need a reminder of how to do this, revisit the Getting Started Course. Insert the code below.
Not your programming language? Set your preferences so we can display relevant code examples
Write code (C#)
Copy the code below into a new C# project. If you need a reminder of how to do this, revisit the Getting Started Course. Insert the code below.
Not your programming language? Set your preferences so we can display relevant code examples
Write code (Swift)
Copy the code below into a new Swift project. If you need a reminder of how to do this, revisit the Getting Started Course. Insert the code below.
Not your programming language? Set your preferences so we can display relevant code examples
Try running your program. Place your phone over the light sensor and note the change in illuminance. You will use this change in the next step.
Track Screen Time
To track your screen time, you will need to introduce a timer into your code. The difference between the time the phone is removed and replaced is how long the phone was active. If you keep a running total of your active minutes, you can keep track of your overall screen time.
Add a timer to your program and alert your user to their total screen time in minutes every time they place their phone on the Light Phidget.

time.time()
provides the time since your program started in seconds.
System.nanoTime()
provides the time since your program started in nanoseconds. 1 nanosecond is 10^-9 seconds. To get the time in seconds use: (System.nanoTime * Math.pow(10,-9))
- add
using System.diagnostics;
at the top of your program - Create a new stopwatch and start the timer just after your open call before you use your Phidgets:
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
stopwatch.ElapsedMilliseconds
will provide you with the time since you started the timer in milliseconds. To convert to seconds use:(stopwatch.ElapsedMilliseconds/1000)
To record the current time use: let time = DispatchTime.now()
. To use or print the time recorded in seconds use: Double(time.uptimeNanoseconds)/1000000000