A step-counting library for the Playdate
To install PdSteps, copy the "PdSteps.lua" file into your project and import it with this line of code:
import "Path/to/the/lua/file"To work, the Playdate must be in the pocket of the user.
According to a video review of pd-steps by Playdate Player on YouTube, after a walk around the park, I the amount of steps PD-steos said had been walked was exactly the same as a pedometer from Amazon though it differed by a bit compared to the pedometer on his phone.
To start tracking the steps, you need the following lines:
--Import timer from CoreLibs
import "CoreLibs/timer"
--Import PdSteps itself
import "Path/To/PdSteps"
--Start checking steps after 15000 milliseconds ( 15 seconds )
PdSteps:StartStepChecking( 15000 )
function playdate.update()
--Update all timers so PdSteps can work
playdate.timer.updateTimers()
endSo this piece of code will start tracking the steps, but it doesn't display the steps. For that, we'll use this piece of code:
--Import timer and graphics from CoreLibs
import "CoreLibs/timer"
import "CoreLibs/graphics"
--Import PdSteps itself
import "Path/To/PdSteps"
--Start checking steps after 15000 milliseconds ( 15 seconds )
PdSteps:StartStepChecking( 15000 )
function playdate.update()
--Clear the screen
playdate.graphics.clear()
--Update all timers so PdSteps can work
playdate.timer.updateTimers()
--Display the steps
playdate.graphics.drawText( tostring( PdSteps:GetSteps()), 200, 120 )
endYAY! You made a working pedometer for the Playdate!
This section goes through all the functions and features
PdSteps:GetSteps()Returns the number of steps taken as an integer.
PdSteps:GetTrackingStatus()Returns whether or not steps are being tracked as a boolean.
PdSteps:ResetSteps()Sets steps to 0.
PdSteps:StartStepChecking( Delay )Starts to check steps after delay, this includes disabling screen auto lock and starting the accelerometer. The delay needs to be in milliseconds.
PdSteps:StopStepChecking()Stops checking the steps, which includes turning off the accelerometer and disabling the auto lock.
PdSteps:IncreaseSteps( Amount )Increases the steps by amount.
PdSteps:DecreaseSteps( Amount )Decreases the steps by amount.
I hope that in the future people use this library to make fun and interesting games that take up full use of the Playdate's capabilities. From Finley