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;
- #define POTENCIOMETAR A0
- #define BTN 4
- #define SW 2
- typedef void interruptFunction();
- int br = 0,
- btn_start_time,
- btn_old_state,
- btn_check_id,
- sw_old_state;
- interruptFunction* sw_rising_func = NULL,
- * sw_falling_func = NULL;
- void btn_check(int id, void* ptrt){
- if(btn_old_state < digitalRead(BTN)){
- btn_start_time = millis();
- btn_old_state = digitalRead(BTN);
- }else if(btn_old_state > digitalRead(BTN)){
- if(millis() - btn_start_time >= 2000){
- br += analogRead(POTENCIOMETAR);
- Serial.print("Vrednost br je: ");
- Serial.println(br);
- }
- btn_old_state = digitalRead(BTN);
- }
- }
- void turn_all_LED_off(){
- for(int i = 26; i <= 33; ++i){
- digitalWrite(i, LOW);
- }
- }
- void sw_attach_interrupt(short mode, interruptFunction func){
- if(mode == RISING){
- sw_rising_func = func;
- }else if(mode == FALLING){
- sw_falling_func = func;
- }
- }
- void sw_rising(){
- turn_all_LED_off();
- int dec = map(analogRead(POTENCIOMETAR), 0, 1023, 0, 255);
- //Serial.println(dec); -> SAMO ZA TESTIRANJE <-
- int i = 26;
- while(dec / 2 != 0 || i <= 33){
- digitalWrite(i++, dec % 2);
- dec /= 2;
- }
- }
- void sw_check(int id, void* ptrt){
- if(sw_old_state < digitalRead(SW)){
- sw_rising_func();
- sw_old_state = digitalRead(SW);
- }else if(sw_old_state > digitalRead(SW)){
- sw_old_state = digitalRead(SW);
- }
- }
- void serial_check(int id, void* ptrt){
- if(Serial.available()){
- int broj = atoi(Serial.readString());
- if(broj < br){
- setTaskState(btn_check_id, TASK_DISABLE);
- Serial.println("Broj koji je unet je manji od br. (onemogucavam task za btn 4)");
- }
- }
- }
- void setup()
- {
- Serial.begin(9600);
- for(int i = 26; i <= 33; ++i){
- pinMode(i, OUTPUT);
- }
- btn_old_state = digitalRead(BTN);
- sw_old_state = digitalRead(SW);
- sw_attach_interrupt(RISING, sw_rising);
- btn_check_id = createTask(btn_check, 50, TASK_ENABLE, NULL);
- createTask(sw_check, 50, TASK_ENABLE, NULL);
- createTask(serial_check, 500, TASK_ENABLE, NULL);
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment