Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<arduinoPlatform.h>
- #include<tasks.h>
- #include<interrupts.h>
- #include<stdio.h>
- #include<serial.h>
- #include <pwm.h>
- #include<data.h>
- extern serial Serial;
- typedef void interruptFunction();
- #define BTN1 4
- #define LD2 27
- short BTN1_old_state;
- interruptFunction *falling_edge_function = NULL,
- *rising_edge_function = NULL;
- bool attachInterrupt_BTN1(interruptFunction *func, int edge_mode){
- if(edge_mode == RISING){
- rising_edge_function = func;
- return true;
- }else if(edge_mode == FALLING){
- falling_edge_function = func;
- return true;
- }
- return false;
- }
- bool detachInterrupt_BTN1(int edge_mode){ //u potpunosti nepotrebna funckija za zadatak...
- if(edge_mode == RISING && rising_edge_function != NULL){
- rising_edge_function = NULL;
- return true;
- }else if(edge_mode == FALLING && falling_edge_function != NULL){
- falling_edge_function = NULL;
- return true;
- }
- return false;
- }
- void interruptRising(){
- digitalWrite(LD2, HIGH);
- }
- void interruptFalling(){
- digitalWrite(LD2, LOW);
- }
- void button_task(int id, void *ptrt){
- int new_state = digitalRead(BTN1);
- if(BTN1_old_state < new_state){
- if(rising_edge_function != NULL){
- rising_edge_function();
- }
- }else if(BTN1_old_state > new_state){
- if(falling_edge_function != NULL){
- falling_edge_function();
- }
- }
- if(BTN1_old_state != new_state){
- BTN1_old_state = new_state;
- }
- }
- void setup()
- {
- BTN1_old_state = digitalRead(BTN1);
- attachInterrupt_BTN1(interruptFalling, FALLING);
- attachInterrupt_BTN1(interruptRising, RISING);
- createTask(button_task, 50, TASK_ENABLE, NULL);
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment