Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Ticker.h>
- Ticker timer0;
- Ticker timer1;
- //local send_pin = 4 --GPIO2
- #define send_pin 4
- //local float_pin = 3 --GPIO0
- #define float_pin 3
- void setup(){
- Serial.begin(115200);
- //gpio.mode(send_pin,gpio.OUTPUT)
- pinMode(send_pin,OUTPUT);
- //gpio.mode(float_pin,gpio.INT)
- pinMode(float_pin,INPUT);
- //counter = 0
- counter = 0;
- //comanda = 0
- comanda = 0;
- }
- //function print_comanda()
- void print_comanda() {
- //tmr.alarm(0, 500, 0, function() //TODO
- //ADDED AT LOOP
- //timer0.attach(500, print_comanda)
- //print("comanda = ", comanda)
- Serial.print("comanda = ");
- Serial.println(comanda);
- //comanda = 0
- comanda = 0;
- timer0.detach();
- //end)
- //end
- }
- //function incr_comanda()
- void incr_comanda() {
- //tmr.alarm(1, 50, 0, function() //TODO
- //ADDED AT LOOP
- //timer1.attach(50, incr_comanda)
- //if counter > 3 then
- if(counter > 3){
- //comanda = comanda + 1
- comanda++;
- //counter = 0
- counter = 0;
- //tmr.stop(1) //TODO
- timer1.detach();
- //end
- }
- //end)
- //end
- }
- //function test()
- void test() {
- //if gpio.read(float_pin) == gpio.HIGH then
- if(digitalRead(float_pin) == HIGH)
- //counter = counter + 1
- counter++;
- //incr_comanda()
- incr_comanda();
- //print_comanda()
- print_comanda();
- //end
- }
- //end
- }
- void loop(){
- //pwm.setup(send_pin, 1000, 512)
- analogWrite(send_pin, 128); //I don't know if this is the right value
- //pwm.start(send_pin) // Not needed
- //gpio.trig(float_pin,"both",test)
- attachInterrupt(float_pin,test,CHANGE);
- timer0.attach(500, print_comanda);
- timer1.attach(50, incr_comanda);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement