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;
- int x1 = 0,
- x2 = 0;
- const int POTENCIOMETAR = A0;
- int fun1(){
- int p_value = analogRead(POTENCIOMETAR);
- int m_value = map(p_value, 0, 1023, 0, 8);
- return m_value;
- }
- 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 br_lampica = x1 = fun1();
- for(int i = 1, j = 26; i <= br_lampica || j <= 33; ++i, ++j){
- if(i <= br_lampica){
- digitalWrite(j, HIGH);
- }else{
- digitalWrite(j, LOW);
- }
- }
- 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 c = Serial.read();
- if(c >= '0' && c <= '9'){
- Serial.print(c);
- }
- }
- BTN2_old_state = digitalRead(BTN2);
- }else if(BTN2_old_state > digitalRead(BTN2)){
- BTN2_old_state = digitalRead(BTN2);
- }
- }
- typedef void interruptFunction();
- const int SW1 = 2;
- int sw1_old_state,
- task1_id;
- interruptFunction *sw1_rising_edge = NULL,
- *sw1_falling_edge = NULL;
- void sw1_attach_interrupt(short mode, interruptFunction* func){
- if(mode == RISING){
- sw1_rising_edge = func;
- }else if(mode == FALLING){
- sw1_falling_edge = func;
- }
- }
- void sw1_check(int id, void* ptrt){
- if(sw1_old_state < digitalRead(SW1)){
- if(sw1_rising_edge != NULL){
- sw1_rising_edge();
- }
- sw1_old_state = digitalRead(SW1);
- }else if(sw1_old_state > digitalRead(SW1)){
- if(sw1_falling_edge != NULL){
- sw1_falling_edge();
- }
- sw1_old_state = digitalRead(SW1);
- }
- }
- void sw1_int_on(){ //uzlazna ivica
- setTaskState(task1_id, TASK_DISABLE);
- for(int i = 26; i <= 33; ++i){
- digitalWrite(i, LOW);
- }
- for(int i = 26; i <= 33; ++i){
- digitalWrite(i, HIGH);
- delay(100 * x1);
- digitalWrite(i, LOW);
- }
- }
- void sw1_int_off(){
- setTaskState(task1_id, TASK_ENABLE);
- }
- const int BTN3 = 36;
- int BTN3_old_state,
- BTN3_start_time;
- 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){
- Serial.println("NRS");
- }
- BTN3_old_state = digitalRead(BTN3);
- }
- }
- void setup()
- {
- Serial.begin(9600);
- for(int i = 26; i <= 33; ++i){
- pinMode(i, OUTPUT);
- digitalWrite(i, LOW);
- }
- BTN1_old_state = digitalRead(BTN1);
- BTN2_old_state = digitalRead(BTN2);
- task1_id = createTask(task1, 50, TASK_ENABLE, NULL);
- sw1_old_state = digitalRead(SW1);
- sw1_attach_interrupt(RISING, sw1_int_on);
- sw1_attach_interrupt(FALLING, sw1_int_off);
- createTask(sw1_check, 50, TASK_ENABLE, NULL);
- BTN3_old_state = digitalRead(BTN3);
- createTask(task2, 25, TASK_ENABLE, NULL);
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment