Advertisement
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 z1 = 0,
- z2 = 0;
- /*----------------------------------*/
- /*============= DRUGA TACKA =========*/
- const int POTENCIOMETAR = A0;
- int fun1(){
- int p_value = analogRead(POTENCIOMETAR);
- int map_value = map(p_value, 0, 1023, 0, 255);
- return map_value;
- }
- /*====================================*/
- /*~~~~~~~~~~~~ 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)){
- int dec = fun1(),
- i = 26;
- z1 = dec;
- while(dec / 2 > 0 || i <= 33){ //iz decimalnog broja u binarni broj
- digitalWrite(i++, dec % 2);
- dec /= 2;
- }
- Serial.println("BTN1 je upravo pritisnut.");
- BTN1_old_state = digitalRead(BTN1);
- }else if(BTN1_old_state > digitalRead(BTN1)){
- BTN1_old_state = digitalRead(BTN1);
- }
- if(BTN2_old_state < digitalRead(BTN2)){
- if(Serial.available()){
- char *s = Serial.readString();
- Serial.println(s);
- }
- BTN2_old_state = digitalRead(BTN2);
- }else if(BTN2_old_state > digitalRead(BTN2)){
- BTN2_old_state = digitalRead(BTN2);
- }
- }
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /*********** CETVRTA TACKA **************/
- typedef void interruptFunction();
- const int SW1 = 2;
- int task1_id,
- sw1_old_state;
- interruptFunction* sw1_rising_edge = NULL,
- * sw1_falling_edge = NULL;
- void sw1_attach_interrupt(int mode, interruptFunction* func){
- if(mode == RISING){
- sw1_rising_edge = func;
- }else if(mode == FALLING){
- sw1_falling_edge = func;
- }
- }
- void sw1_rising_edge_func(){
- setTaskState(task1_id, TASK_DISABLE);
- for(int i = 26; i <= 33; ++i){
- digitalWrite(i, LOW);
- }
- for(int i = 33; i >= 26; --i){
- digitalWrite(i, HIGH);
- delay(z1 * 100);
- digitalWrite(i, LOW);
- }
- }
- void sw1_falling_edge_func(){
- for(int i = 26; i <= 33; ++i){
- digitalWrite(i, LOW);
- }
- setTaskState(task1_id, TASK_ENABLE);
- }
- void sw1_check(int id, void* ptrt){
- if(sw1_old_state < digitalRead(SW1)){
- sw1_rising_edge();
- sw1_old_state = digitalRead(SW1);
- }else if(sw1_old_state > digitalRead(SW1)){
- sw1_falling_edge();
- sw1_old_state = digitalRead(SW1);
- }
- }
- /**************************************/
- /*-=-=-=-=-=-=-= PETA TACKA =-=-=-=-=-=*/
- 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 >= 1500){
- ++z2;
- Serial.print("z2=");
- Serial.println(z2);
- }
- 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");
- /*----------------------------------*/
- /*~~~~~~~~~~~~ TRECA TACKA ~~~~~~~~~*/
- BTN1_old_state = digitalRead(BTN1);
- BTN2_old_state = digitalRead(BTN2);
- task1_id = createTask(task1, 50, TASK_ENABLE, NULL);
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /*********** CETVRTA TACKA **************/
- sw1_old_state = digitalRead(SW1);
- sw1_attach_interrupt(RISING, sw1_rising_edge_func);
- sw1_attach_interrupt(FALLING, sw1_falling_edge_func);
- createTask(sw1_check, 50, TASK_ENABLE, NULL);
- /***************************************/
- /*-=-=-=-=-=-=-= PETA TACKA =-=-=-=-=-=*/
- BTN3_old_state = digitalRead(BTN3);
- createTask(task2, 30, TASK_ENABLE, NULL);
- /*=-=-=-=-=-=-=-=-==-=-=-=-=-=--=-==-=-=-=*/
- }
- void loop()
- {
- }
Advertisement
Advertisement