1 Replies - 307 Views - Last Post: 28 October 2011 - 09:50 AM Rate Topic: -----

#1 TEH  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 151
  • Joined: 30-January 08

Is there any Timers like VB.Net in C/C++

Posted 28 October 2011 - 09:30 AM

I have been thinking and searching information about how could I calculate time and do some processes meanwhile with AVR.
I have created example code of what I want with VB.NET but I have no idea how to make the same functionality with C/C++.

Here's my VB.NET code
 
 Dim i As Integer

    Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
        LED2 = ON;
        Timer1.Stop()
        i = 0
    End Sub

    Private Sub Timer2_Tick(sender As Object, e As System.EventArgs) Handles Timer2.Tick
        i = 0
        Timer1.Stop()
    End Sub

    Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Timer1.Stop()
        Timer2.Start()
        i = i + 1

        If i < 5 Then
            Timer1.Interval = 500
            Timer1.Start()
            Timer2.Interval = 5000
        Else
            LED1 = ON;
            Timer1.Stop()
            i = 0
            Timer2.Interval = 5000

        End If
        If i = 2 Then
            LED1 = ON;
        End If
    End Sub

    Private Sub Form1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        Timer1.Stop()
        LED2 = OFF;
    End Sub


I have cleaned some lines out of this code but I attach the original VB.NET project to this message.
Attached File  avr.zip (65.17K)
Number of downloads: 18
In that code I ave used mousebutoon as a button, but meaning is that:
  • When I press button 5 times in 5 seconds LED1 lights on and stays.
  • When I press and hold same button over 0,5seconds LED2 lights on and stays on as long as I pres the button.
  • When I press button 2 times in 5 seconds LED1 lights off.


Variable i will be set to 0 after each 5 seconds.

Is there any way of doing that in C and if is what I need to learn and search. I havent found any timer-functions from C, but I can't figure out how else could this be done. Suggestions, help, ideas, anything?

This post has been edited by TEH: 28 October 2011 - 09:30 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Is there any Timers like VB.Net in C/C++

#2 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 31-December 10

Re: Is there any Timers like VB.Net in C/C++

Posted 28 October 2011 - 09:50 AM

This may be what you are looking for:
http://www.cplusplus...m/beginner/317/

other suggestions here:
http://www.cplusplus...m/general/8255/
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1