Pages: [1]   Go Down
Author Topic: Using timers and counters.  (Read 413 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got a project where I want to count a signal from a shock sensor for 5 seconds.

Push the button
delays 3 seconds
Outputs a buzzer
starts 5 second timer
counts number of inputs from sensor
buzzes again at 5 seconds
outputs number of hits to lcd.

I don't expect anyone to do it for me but I'd sure appreciate it if someone would point me in the right direction.

Thanks guys
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lots of ways to implement a counter:
   int i = 0;
   i = i + 1;  // Increase counter by 1
   i += 1;     // Increase counter by 1
   i++;        // Increase counter by 1

For a timer:
   unsigned long startTime = millis();

  if (millis() - startTime > 5000)  // 5-second timer has expired
       {
       }
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

Would you know of any project on-line that uses this method that I could modify for my use?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, the BlinkWithoutDelay example (File->Examples->2.Digital->BlinkWithoutDelay) would be a good place to start.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: