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>
- extern serial Serial;
- #define SW1 2
- #define SW2 7
- #define SW3 8
- #define SW4 35
- #define btn1 4
- int vrednost,brojac;
- int staro_stanje,novo_stanje;
- void fun(){
- int pocentiometar=analogRead(A0);
- vrednost=map(pocentiometar,0,1023,0,8);
- for(int i=0;i<vrednost;i++){
- digitalWrite(26+i,HIGH);
- }
- for(int j=vrednost;j<=33;j++) digitalWrite(26+j,LOW);
- }
- void fun2(){
- if(digitalRead(SW1)==HIGH) ++brojac;
- if(digitalRead(SW2)==HIGH) ++brojac;
- if(digitalRead(SW3)==HIGH) ++brojac;
- if(digitalRead(SW4)==HIGH) ++brojac;
- Serial.println("Broj upaljenih prekidaca:");
- Serial.println(brojac);
- brojac=0;
- }
- void task1(int n,void *tptr){
- fun();
- novo_stanje=digitalRead(btn1);
- if(staro_stanje==0 && novo_stanje==1){
- Serial.println("Vrednost pot 0-100%");
- Serial.println(vrednost*10+20);
- }
- novo_stanje=staro_stanje;
- }
- void setup()
- {
- brojac=0;
- Serial.begin(9600);
- pinMode(SW1,INPUT);
- pinMode(SW2,INPUT);
- pinMode(SW3,INPUT);
- pinMode(SW4,INPUT);
- pinMode(A0,INPUT);
- staro_stanje=digitalRead(btn1);
- for(int i=0;i<8;i++) pinMode(26+i,OUTPUT);
- createTask(task1,50,TASK_ENABLE,NULL);
- attachInterrupt(1,fun2,RISING);
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement