True/False game
Create a list of true or false questions. Your program should ask a question, wait for the player to answer (green = true, red = false), provide feedback using the LEDs (correct = green vs incorrect = red), record a score (1 for correct, 0 for incorrect), then ask the next question. At the end of the game, your LEDs should flash 5 times and the score will be displayed.
Whack-A-Mole game
Create a program that randomly lights up an LED and waits for the corresponding button to be pushed.
- After the corresponding button has been pushed, turn off the LED and randomly activate one again.
- Time how long it takes players to hit the button. Create a final score from the times.
time.time()
provides the time since your program started in seconds.
Not your programming language? Set your preferences so we can display relevant code examples
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))
Not your programming language? Set your preferences so we can display relevant code examples
- 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)
Not your programming language? Set your preferences so we can display relevant code examples
To record the current time use: let time = Dispatch.now()
. To use or print the time recorded in seconds use: time.uptimeNanoseconds/1000000000
Not your programming language? Set your preferences so we can display relevant code examples
Simon Says game
Make a simple Simon Says style game. The box should display a random sequence of LED flashes and the user should repeat this pattern by pressing the appropriate buttons.
- The sequence should begin at length one and increase in size by 1 every time the correct sequence is entered.
- If the sequence reaches a certain length, a message should appear on the console notifying the player that he or she has won.
Stopwatch
Create a program that allows you to start a timer, pause a timer and reset the timer. A green button press should start the timer. The red button press should pause the timer. If both buttons are pressed the timer should stop. When the timer is running the green LED should be on. When the timer is paused the Red LED should be on. When the timer is reset both LEDs should flash then turn off. For each button press, you should print the time in seconds to the user.
time.time()
provides the time since your program started in seconds.
Not your programming language? Set your preferences so we can display relevant code examples
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))
Not your programming language? Set your preferences so we can display relevant code examples
- 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)
Not your programming language? Set your preferences so we can display relevant code examples
To record the current time use: let time = Dispatch.now()
. To use or print the time recorded in seconds use: time.uptimeNanoseconds/1000000000
Not your programming language? Set your preferences so we can display relevant code examples
Troubleshoot
- Make sure everything is plugged in properly and your VINT Hub is connected to your computer
- Check to make sure you are connected to the correct Hub Port on your VINT Hub. In this case your Red Button should be connected to Hub Port 0.
- Stop running other programs that are using your Phidgets before running a program.
- Check the button assembly. If the switch and button are not assembled correctly you will not see any button events. The plastic plunger should align with the activator as shown below.
If these do not solve your issue visit the Advanced Troubleshooting Page.