0

I am making a BCI system i Windows Form Application in Visual Studio, and I ned my buttons to flicker between black and white on the Back.Color. I need to have the opportunity to set the flickering to a predefined frequency, and ther flickering to follow a square wave form. At the moment I am using a timer to get the flickering, however it is just to see if the interface looks the way it should.

Is this possible ? and can anyone help wiht this?

Here is my flicker code at the moment:

    timer11.Start();
    timer11.Interval = 37;
    timer11.Enabled = true;

    private void timer11_Tick(object sender, EventArgs e)
    {           
        if (BlinkOn)
        {
            Exit.ForeColor = Color.Black;
            Exit.BackColor = Color.White;
        }
        else
        {
            Exit.ForeColor = Color.White;
            Exit.BackColor = Color.Black;
        }
        BlinkOn = !BlinkOn;
    }

I need this to be rewritten into a square wave form, where I can specify the frequency I need. I am a novice in C#, so this was the easiet for to start with, however I need it to be flickering of a square wave form. I have seen some examples in UnityEngine, however I am writing in Wondows Form.

Thanks.

Microsoft DN
  • 9,706
  • 10
  • 51
  • 71
Aslak
  • 21
  • 2
    You're acting like you think something's *wrong* with using a timer. I don't know where you get that idea. A timer is the correct way to do this. You've already got a square wave (although it's silly that you set the color twice each time the timer fires -- only the second assignment will do anything), and you're already controlling the frequency. What more do you want this code to do? – Joe White Apr 16 '15 at 13:45
  • The problem is that using a `Timer` is not guaranteed to be precise; it's just approximate. This is especially noticeable for short intervals. .NET is not a real-time language; this may not even be possible (if .NET decides that it's time to garbage-collect, nothing will happen) See http://stackoverflow.com/a/9228399/1108056 – AnotherParker Apr 16 '15 at 14:30
  • 1
    Since this is for indication to a human operator, I don't see anything wrong with this approach. You will not use (and will not want to use) frequencies of more than a couple Hertz, or you'll risk your operator may experience epilepsy seizures. If you have the frequency of your square wave and have to find the timer period (in milliseconds), you can use a simple formula: T = 1000 / F. Here T is your calculated period, and F the frequency in Hertz. – Alex Mazzariol Apr 16 '15 at 15:48

0 Answers0