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;
- /* --------> Prva tacka <--------*/
- int x1 = 0,
- x2 = 0;
- /* -------------------------------*/
- /*========> Druga tacka <==========*/
- const int SW123[] = {2, 7, 8};
- int fun1(){
- int lampica_pin = 26,
- counter = 0;
- for(int i = 0; i < 3; ++i){ //posto proveravamo 3 prekidaca petlja ide do 3
- if(digitalRead(SW123[i])){
- digitalWrite(lampica_pin++, HIGH);
- ++counter;
- }else{
- digitalWrite(lampica_pin++, LOW);
- }
- }
- return counter;
- }
- /*==================================*/
- /********** TRECA TACKA ***************/
- const int BTN1 = 4,
- BTN2 = 34;
- int BTN1_old_state,
- BTN2_old_state;
- void task1(int id, void* ptrt){
- if(BTN1_old_state < digitalRead(BTN1)){
- x1 = fun1();
- Serial.print("task1: x1=");
- Serial.println(x1);
- BTN1_old_state = digitalRead(BTN1);
- }else{
- BTN1_old_state = digitalRead(BTN1);
- }
- if(BTN2_old_state < digitalRead(BTN2)){
- x2 = 2 * x1;
- Serial.print("task1: x2=");
- Serial.println(x2);
- BTN2_old_state = digitalRead(BTN2);
- }else{
- BTN2_old_state = digitalRead(BTN2);
- }
- }
- /**************************************/
- /*~~~~~~~~~~~ CETVRTA TACKA ~~~~~~~~~~~~*/
- typedef void interruptFunction();
- interruptFunction* sw4_rising_edge = NULL;
- void sw4_attach_interrupt(interruptFunction* func){
- sw4_rising_edge = func;
- }
- const int SW4 = 35;
- int sw4_old_state;
- void sw4_check(int id, void* ptrt){
- if(sw4_old_state < digitalRead(SW4)){
- if(sw4_rising_edge != NULL){
- sw4_rising_edge();
- }
- sw4_old_state = digitalRead(SW4);
- }else{
- sw4_old_state = digitalRead(SW4);
- }
- }
- void sw4_rising_function(){
- int dec = x1 + x2,
- i = 30;
- while(dec / 2 > 0 || i <= 33){
- digitalWrite(i++, dec % 2);
- dec /= 2;
- }
- Serial.println("interupt SW4");
- }
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /*=-=-=-=-=-=-= PETA TACKA =-=-=-=-=-=-=*/
- void sw4_detach_interrupt(){
- sw4_rising_edge = NULL;
- }
- const int BTN3 = 36;
- int BTN3_start_time,
- BTN3_old_state;
- void task2(int id, void* ptrt){
- if(BTN3_old_state < digitalRead(BTN3)){
- BTN3_start_time = millis();
- BTN3_old_state = digitalRead(BTN3);
- }else if(BTN3_old_state > digitalRead(BTN3)){
- if(millis() - BTN3_start_time >= 2000){
- sw4_detach_interrupt();
- Serial.println("task2: brisanje interupt-a sa prekidaca SW4");
- }
- BTN3_old_state = digitalRead(BTN3);
- }
- }
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- void setup()
- {
- /*------> Prva tacka <------*/
- Serial.begin(9600);
- for(int i = 26; i <= 33; ++i){
- pinMode(i, OUTPUT);
- digitalWrite(i, LOW);
- }
- Serial.println("Martin Muharemovic PR130/2021 - Grupa 7");
- /*--------------------------*/
- /********* TRECA TACKA ************/
- BTN1_old_state = digitalRead(BTN1);
- BTN2_old_state = digitalRead(BTN2);
- createTask(task1, 30, TASK_ENABLE, NULL);
- /**********************************/
- /*~~~~~~~~~~~ CETVRTA TACKA ~~~~~~~~~~~~~*/
- sw4_old_state = digitalRead(SW4);
- sw4_attach_interrupt(sw4_rising_function);
- createTask(sw4_check, 50, TASK_ENABLE, NULL);
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /*=-=-=-=-=-=-= PETA TACKA =-=-=-=-=-=-=*/
- BTN3_old_state = digitalRead(BTN3);
- createTask(task2, 25, TASK_ENABLE, NULL);
- /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
- }
- void loop()
- {
- }
Advertisement
Comments
-
- Фотографија задатка је на линку: https://imgur.com/a/zSvvDoE
Add Comment
Please, Sign In to add comment