Syncing projects with real time

I want to make a program that turns my keyboard into a speed cubing mat ('cause I’m a Rubix Cube freak but don’t want to buy a real mat and timer) but don’t know how to do anything like that.:fox_face:

1 Like

For those who are confused, a Speed Cubing mat is bassicly a fancy timer. For those who are further confused, Speed Cubing is just doing a Rubix Cube very fast (usally with a specialy designed cube).

Help @CodecademyModerators!

Interesting…

#include <iostream>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cstdio>

class Timer
{
public:
    void start()
    {
        m_StartTime = std::chrono::steady_clock::now();
        m_bRunning = true;
    }
    
    void stop()
    {
        m_EndTime = std::chrono::steady_clock::now();
        m_bRunning = false;
    }
    
    double elapsedMilliseconds()
    {
        std::chrono::time_point<std::chrono::steady_clock> endTime;
        
        if(m_bRunning)
        {
            endTime = std::chrono::steady_clock::now();
        }
        else
        {
            endTime = m_EndTime;
        }
        
        return std::chrono::duration_cast<std::chrono::milliseconds>(endTime - m_StartTime).count();
    }
    
    double elapsedSeconds()
    {
        return elapsedMilliseconds() / 1000.0;
    }

private:
    std::chrono::time_point<std::chrono::steady_clock> m_StartTime;
    std::chrono::time_point<std::chrono::steady_clock> m_EndTime;
    bool                                               m_bRunning = false;
};

int main() {
  Timer myTimer;
  std::cout << "Hit enter to start!\n";
  int c;

  do {
    c = getchar();
  } while (c != '\n');

  std::cout << "Starting Clock: " << myTimer.elapsedMilliseconds() << "\n";

  myTimer.start();

  do {
    c = getchar();
  } while (c != '\n');

  myTimer.stop();
  std::cout << "Seconds: " << myTimer.elapsedSeconds();
}

I borrowed the implementation of the Timer class from a gist on GitHub.

Wow. Thanks @thepitycoder ! :muscle: :fox_face: :+1: