Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include the most common headers from the C standard library
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- // Include the main libnx system header, for Switch development
- #include <switch.h>
- // Main program entrypoint
- int main(int argc, char* argv[])
- {
- // This example uses a text console, as a simple way to output text to the screen.
- // If you want to write a software-rendered graphics application,
- // take a look at the graphics/simplegfx example, which uses the libnx Framebuffer API instead.
- // If on the other hand you want to write an OpenGL based application,
- // take a look at the graphics/opengl set of examples, which uses EGL instead.
- consoleInit(NULL);
- // Other initialization goes here.
- printf("Hello World!\n");
- printf("This is a stopwatch\n\n\n");
- printf("**Press 'B' to start.\n");
- printf("**Press 'A' to pause.\n");
- printf("**Press '+' to exit.\n");
- int nSec;
- int nMin;
- int nHrs;
- int nDay;
- struct timespec start_time, end_time;
- clock_gettime(CLOCK_REALTIME, &start_time);
- // Main loop
- while (appletMainLoop()) // Start loop A
- {
- hidScanInput();
- // hidKeysDown returns information about which buttons have been
- // just pressed in this frame compared to the previous one
- u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); // define kDown (press a button)
- u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); // define kHeld (hold a button)
- //Exit:
- if (kDown & KEY_PLUS) // If + is pressed then:
- break; // End loop A and exit application
- // Start:
- if (kDown & KEY_B) // If B is pressed
- {
- while (1) // Start loop B
- {
- hidScanInput();
- u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); // define kDown (press a button)
- u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); // define kHeld (hold a button)
- clock_gettime(CLOCK_REALTIME, &end_time);
- nSec = (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) /1000000000.0;
- nMin = (nSec/60);
- nHrs = (nMin/60);
- nDay = (nHrs/24);
- printf("\r"); // Print new line
- printf("Elapsed: %i Days & %i:%i:%f \r", nDay, nHrs%24, nMin%60, nSec%60); // Print new time
- consoleUpdate(NULL);// Update the console, sending a new frame to the display
- // Stop:
- if (kDown & KEY_A) // If A is pressed then
- break; // End loop B and return to loop A
- } // End loop B
- if (kDown & KEY_B)
- {
- printf("Lap time: %f\n", (nSec/60) % 60); // Print time
- if (kDown); // Wait for input
- }
- else break; // End loop B and exit application if B is not pressed
- }; // Stop timer
- printf("Final Time %f\r", nSec); //display final time
- consoleUpdate(NULL); // Update the console, sending a new frame to the display
- } // End loop A
- /* =============================== END ======================================= */
- printf("\n Goodbye."); // Say goodbye before exiting. (very important!)
- consoleUpdate(NULL);
- svcSleepThread(1e+9L);
- // Deinitialize and clean up resources used by the console (important!)
- consoleExit(NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement