Mozzi  version 2016-12-11-17:03
sound synthesis library for Arduino
CapPoll.h
1 #ifndef RCPOLL_H
2 #define RCPOLL_H
3 
4 
11 template <unsigned char SENSOR_PIN, unsigned char SEND_PIN>
12 class CapPoll
13 {
14 
15 public:
18  CapPoll():result(0),rc_cued(true), output(0)
19  {
20  ;
21  }
22 
28  inline
29  unsigned int next(){
30  if (rc_cued){
31  pinMode(SENSOR_PIN, INPUT); // turn pin into an input and time till pin goes low
32  digitalWrite(SENSOR_PIN, LOW); // turn pullups off - or it won't work
33  rc_cued = false;
34  }
35  if(digitalRead(SENSOR_PIN)){ // wait for pin to go low
36  result++;
37  }
38  else{
39  output = result;
40  result = 0;
41  pinMode(SENSOR_PIN, OUTPUT); // make pin OUTPUT
42  digitalWrite(SENSOR_PIN, HIGH); // make pin HIGH to discharge capacitor - see the schematic
43  rc_cued = true;
44  }
45  return output;
46  }
47 
48 private:
49  unsigned int result;
50  boolean rc_cued;
51  unsigned int output;
52 
53 };
54 
55 #endif // #ifndef RCPOLL_H
56 
CapPoll()
Constructor.
Definition: CapPoll.h:18
A class for reading voltage on a digital pin, derived from http://arduino.cc/en/Tutorial/RCtime.
Definition: CapPoll.h:12
unsigned int next()
Checks whether the capacitor has charged, and returns how long it took for the most recent charge...
Definition: CapPoll.h:29