Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:09+00:00 2026-05-22T03:16:09+00:00

I have a function that controls a bulb. The bulb is programmed to flash

  • 0

I have a function that controls a bulb. The bulb is programmed to flash whenever a key is pressed. However, I want to limit the minimum interval between flashes to prevent the bulb from burning out. The bulb is controlled by a relay switch connected to the serial port, and the code is as follows:

void WINAPI flash (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
    //MATT: Define the serial port procedure
    HANDLE hSerial;

    //MATT: Fire the flash (by initialising and uninitialising the port)
    hSerial = CreateFile("COM1",GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); CloseHandle(hSerial);
}

How do I limit the minimum flash interval in milliseconds (millisecond accuracy is very important)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:16:09+00:00Added an answer on May 22, 2026 at 3:16 am

    You could use a simple variable that keeps the time as reported by QueryPerformanceCounter. The accuracy of QPC is very, very high on most systems. On my system, the frequency is 2.8million- or one tick per ten processor clocks.

    class bulb {
        __int64 clocks;
        __int64 frequency;
    public:
        static const int max_ms_between_flashes = 1;
        bulb() {
            LARGE_INTEGER li;
            QueryPerformanceFrequency(&li);
            frequency = li.QuadPart;
            clocks = 0;
        }
        void flash(...) {
            LARGE_INTEGER li;
            QueryPerformanceCounter(&li);
            if (clocks == 0) { 
                // We are the first time, so set the clocks var
                // and flash the bulb
                clocks = li.QuadPart;       
            } else {
                __int64 timepassed = clocks - li.QuadPart;
                if (timepassed >= (((double)frequency) / (max_ms_between_flashes * 1000))) {
                    // It's been more than 1ms
                    clocks = li.QuadPart;
                    // flash the bulb
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that binds LINQ results to the controls on my form.
I have a simple function that I want to call in the code behind
Is there any function to recognize that two controls have overlap in xcode? i
I am creating my first plugin and have a single function that controls the
I have a control that has a Filter property that expects a function that
I have a function that adds eventhandlers to control events. Right now I have
I have a custom control that has the following prototype. Type.registerNamespace('Demo'); Demo.CustomTextBox = function(element)
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.