Advertisement
Guest User

ESP_CAPACITIVE_FUNCTION_TEST_ARDUINO_TICKER

a guest
Jun 25th, 2015
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <Ticker.h>
  2.  
  3. Ticker timer0;
  4. Ticker timer1;
  5.  
  6. //local send_pin = 4 --GPIO2
  7. #define send_pin 4
  8. //local float_pin = 3 --GPIO0
  9. #define float_pin 3
  10.  
  11. void setup(){
  12.     Serial.begin(115200);
  13.     //gpio.mode(send_pin,gpio.OUTPUT)
  14.     pinMode(send_pin,OUTPUT);
  15.     //gpio.mode(float_pin,gpio.INT)
  16.     pinMode(float_pin,INPUT);
  17.     //counter = 0
  18.     counter = 0;
  19.     //comanda = 0
  20.     comanda = 0;
  21. }
  22. //function print_comanda()
  23. void print_comanda() {
  24.  //tmr.alarm(0, 500, 0, function()  //TODO
  25.  //ADDED AT LOOP
  26.  //timer0.attach(500, print_comanda)
  27.  
  28.  
  29.  //print("comanda = ", comanda)
  30.  Serial.print("comanda = ");
  31.  Serial.println(comanda);
  32.  
  33.  //comanda = 0
  34.  comanda = 0;
  35.  
  36.  timer0.detach();
  37.  //end)
  38. //end
  39. }
  40.  
  41. //function incr_comanda()
  42. void incr_comanda() {
  43.  //tmr.alarm(1, 50, 0, function() //TODO
  44.  //ADDED AT LOOP
  45.  //timer1.attach(50, incr_comanda)
  46.  
  47.  //if counter > 3 then
  48.  if(counter > 3){
  49.     //comanda = comanda + 1
  50.     comanda++;
  51.     //counter = 0
  52.     counter = 0;
  53.    
  54.     //tmr.stop(1)  //TODO
  55.     timer1.detach();
  56.    
  57.  //end
  58.  }
  59.  //end)
  60. //end
  61. }
  62.  
  63. //function test()
  64. void test() {
  65.  //if gpio.read(float_pin) == gpio.HIGH then
  66.  if(digitalRead(float_pin) == HIGH)
  67.     //counter = counter + 1
  68.     counter++;
  69.     //incr_comanda()
  70.     incr_comanda();
  71.     //print_comanda()
  72.     print_comanda();
  73.  //end
  74.  }
  75. //end
  76. }
  77.  
  78. void loop(){
  79. //pwm.setup(send_pin, 1000, 512)
  80. analogWrite(send_pin, 128); //I don't know if this is the right value
  81. //pwm.start(send_pin)  // Not needed
  82.  
  83. //gpio.trig(float_pin,"both",test)
  84. attachInterrupt(float_pin,test,CHANGE);
  85.  
  86. timer0.attach(500, print_comanda);
  87. timer1.attach(50, incr_comanda);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement