• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Sterowania zakresem temperatury
#1
Serwus, to znowu ja. Wink

Tak jak pisałem w poprzednim wątku, od dwóch dni siedzę i rozkminiam, jak przerobić Wojtka funkcje sterowania zakresem temperatury:

Kod:
if (used.item.getName() == " Temperatura") // dokładnie taki sam ciąg " Temperatura"
     {
       int temp=21; // tu zamiast tego odczytujesz temperaturę np z Dallasa i pokazujesz poniżej
       lcd.setCursor(0,0);lcd.write(7); // wyswietlamy nasz symbol strzałki góra-dół
       lcd.print(" ");lcd.setCursor(1,0);lcd.print("Ust.temp. = "); // tekst dla użytkownika
       lcd.setCursor(13,0);lcd.print(temp); // wyświetlamy akt. temperaturę
       int akcja=-1;delay(1000); // zmienna pomocnicza, sterująca dla petli while
                                          // jesli nie puścisz klawisza OK w ciągu 1 sek. to powrót do menu
       while(akcja!=4) // ta pętla trwa tak długo aż wciśniesz klawisz OK
        {
          zm=-1;
          akcja=czytaj_1(0);//delay(300); // odczyt stanu klawiatury - funkcja czytaj_1 lub czytaj_2 lub czytaj_3
                                           // opis poniżej przy 3 różnych definicjach funkcji czytaj
          if(zm!=akcja) // ruszamy do pracy tylko wtedy gdy zmienił sie stan klawiatury
            {
            if (akcja==1) {temp++;if(temp>99)temp=99;lcd.setCursor(13,0);lcd.print(temp);delay(300);}
              // jesli akcja=1 (czyli wciśnieto klawisz w górę to zwiększono temperaturę
              // ustawiono max próg i wyświetlono obecną temperaturę
            if(akcja==2) {temp--;if(temp<10)temp=10;lcd.setCursor(13,0);lcd.print(temp);delay(300);}
              // jesli akcja=2 (czyli wciśnięto klawisz w dół to mniejszono temperaturę
              // ustawiono min próg i wyświetlono obecną temperaturę
            if(akcja==4) // jeśli wciśnieto OK
              {
                lcd.setCursor(0,0);lcd.print("*Temperatura OK");delay(2000); // pokazujemy OK przez 2 sek.
                lcd.setCursor(1,0);lcd.print(" "); // czyścimy linię
                lcd.setCursor(1,0);lcd.print(linia1); // odtwarzamy poprzedni stan na LCD
               // ... i UWAGA --- tutaj zapsiujemy np. temperaturę do pamięci EEPROM, wykonujemy jakieś
               // inne działanie, czyli de facto nasz podprogram :-)
              }
            }
        } zm=akcja;  // aktualizacja zmiennej zm, po to aby reagować tylko na zmiany stanu klawiatury
        // tu WAŻNY MOMENT - kończy się pętla while i zwracamy sterowanie do głównej pętli loop()
     }

pod tą nawigacje i odczyt przycisków:

Kod:
void  readButtons(){  //read buttons status
 int reading;
 int buttonEnterState=LOW;             // the current reading from the Enter input pin
 int buttonEscState=LOW;             // the current reading from the input pin
 int buttonLeftState=LOW;             // the current reading from the input pin
 int buttonRightState=LOW;             // the current reading from the input pin

 //Enter button
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinEnter);

                 // check to see if you just pressed the enter button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonEnterState) {
                   // reset the debouncing timer
                   lastEnterDebounceTime = millis();
                 }
                 
                 if ((millis() - lastEnterDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonEnterState=reading;
                   lastEnterDebounceTime=millis();
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonEnterState = reading;
                 

   //Esc button              
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinEsc);

                 // check to see if you just pressed the Down button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonEscState) {
                   // reset the debouncing timer
                   lastEscDebounceTime = millis();
                 }
                 
                 if ((millis() - lastEscDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonEscState = reading;
                   lastEscDebounceTime=millis();
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonEscState = reading;
                 
                   
  //Down button              
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinRight);

                 // check to see if you just pressed the Down button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonRightState) {
                   // reset the debouncing timer
                   lastRightDebounceTime = millis();
                 }
                 
                 if ((millis() - lastRightDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonRightState = reading;
                  lastRightDebounceTime =millis();
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonRightState = reading;                  
                 
                 
   //Up button              
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinLeft);

                 // check to see if you just pressed the Down button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonLeftState) {
                   // reset the debouncing timer
                   lastLeftDebounceTime = millis();
                 }
                 
                 if ((millis() - lastLeftDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonLeftState = reading;
                   lastLeftDebounceTime=millis();;
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonLeftState = reading;  

                 //records which button has been pressed
                 if (buttonEnterState==HIGH){
                   lastButtonPushed=buttonPinEnter;

                 }else if(buttonEscState==HIGH){
                   lastButtonPushed=buttonPinEsc;

                 }else if(buttonRightState==HIGH){
                   lastButtonPushed=buttonPinRight;

                 }else if(buttonLeftState==HIGH){
                   lastButtonPushed=buttonPinLeft;

                 }else{
                   lastButtonPushed=0;
                 }
}

void navigateMenus() {
 MenuItem currentMenu=menu.getCurrent();

 switch (lastButtonPushed){
   case buttonPinEnter:
     if(!(currentMenu.moveDown())){  //if the current menu has a child and has been pressed enter then menu navigate to item below
       menu.use();
     }else{  //otherwise, if menu has no child and has been pressed enter the current menu is used
       menu.moveDown();
      }
     break;
   case buttonPinEsc:
     if(!(currentMenu.moveUp())){
       menu.toRoot();
     }else{
       menu.moveUp();
      }
     break;
   case buttonPinRight:
     menu.moveRight();
     break;
   case buttonPinLeft:
     menu.moveLeft();
     break;
 }
 lastButtonPushed=0; //reset the lastButtonPushed variable
}

Z czym mam w chwilo obecnej problem, to odczyt stanu przycisków:

Kod:
          zm=-1;
          akcja=czytaj_1(0);//delay(300); // odczyt stanu klawiatury - funkcja czytaj_1 lub czytaj_2 lub czytaj_3
                                           // opis poniżej przy 3 różnych definicjach funkcji czytaj
          if(zm!=akcja) // ruszamy do pracy tylko wtedy gdy zmienił sie stan klawiatury

nie wiem co wstawić zamiast funkcji akcja=czytaj_1(0). I czy dobrze wnioskuje, że główny problem leży w odczycie stanu przyycisków?

Poniżej cały mój sketch:

Kod:
/*
   Copyright Giuseppe Di Cillo (www.coagula.org)
   Contact: dicillo@coagula.org
   
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
IMPORTANT: to use the menubackend library by Alexander Brevig download it at http://www.arduino.cc/playground/uploads/Profiles/MenuBackend_1-4.zip and add the next code at line 195
    void toRoot() {
        setCurrent( &getRoot() );
    }
*/
#include <MenuBackend.h>    //MenuBackend library - copyright by Alexander Brevig
#include <DS1307RTC.h>
#include <Time.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DS1307_ADDRESS 0x68

#define ONE_WIRE_BUS 12
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

const int buttonPinLeft = 4;      // pin for the Up button
const int buttonPinRight = 3;    // pin for the Down button
const int buttonPinEsc = 5;     // pin for the Esc button
const int buttonPinEnter = 2;   // pin for the Enter button

int lastButtonPushed = 0;

volatile int zm =-1;               // to dla kontroli zmiany stanu klawiatury
volatile int x=-1;                 // zmienna pomocnicza


int temp=21; // tu ustawiam temperaturę
int went_1 = 8; // pin przekaznika wentylatora 1
int went_2 = 9; // pin przekaznika wentylatora 2


int lastButtonEnterState = LOW;   // the previous reading from the Enter input pin
int lastButtonEscState = LOW;   // the previous reading from the Esc input pin
int lastButtonLeftState = LOW;   // the previous reading from the Left input pin
int lastButtonRightState = LOW;   // the previous reading from the Right input pin

volatile int his_1=0;

byte state = LOW;
const char *monthName[12] = {
 "Sty", "Lut", "Mar", "Kwi", "Maj", "Cze",
 "Lip", "Sie", "Wrz", "Paź", "Lis", "Gru"
};

DeviceAddress P1 = { 0x28, 0xFF, 0xB2, 0x4C, 0x65, 0x14, 0x1, 0x6F };
DeviceAddress P2 = { 0x28, 0xFF, 0xE, 0x97, 0x65, 0x14, 0x1, 0x94 };

long lastEnterDebounceTime = 0;  // the last time the output pin was toggled
long lastEscDebounceTime = 0;  // the last time the output pin was toggled
long lastLeftDebounceTime = 0;  // the last time the output pin was toggled
long lastRightDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 300;    // the debounce time

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//Menu variables
MenuBackend menu = MenuBackend(menuUsed,menuChanged);
//initialize menuitems
MenuItem miTemperatura = MenuItem("Temperatura");   // obiekt klasy MenuItem o nazwie miTemperatura
 MenuItem miT_zal = MenuItem("T zal.");            // itd. dla każdej opcji tworzymy instancję (egzemplarz)
 MenuItem miT_wyl = MenuItem("T wyl.");            // klasy MenuItem
MenuItem miWentylator1 = MenuItem("Wentylator1");
 MenuItem miWen1_zal = MenuItem("Wen1_zal");
 MenuItem miWen1_wyl = MenuItem("Wen1_wyl");
MenuItem miWentylator2 = MenuItem("Wentylator2");
 MenuItem miWen2_zal = MenuItem("Wen2_zal");
 MenuItem miWen2_wyl = MenuItem("Wen2_wyl");

void setup()
{

 Serial.begin(9600);
 sensors.begin();
 sensors.setResolution(P1, 12);
 sensors.setResolution(P2, 12);
 Wire.begin();
 pinMode(went_1, OUTPUT);
 pinMode(went_2, OUTPUT);
 
 pinMode(buttonPinLeft, INPUT);
 pinMode(buttonPinRight, INPUT);
 pinMode(buttonPinEnter, INPUT);
 pinMode(buttonPinEsc, INPUT);
 digitalWrite(went_1, HIGH);
 digitalWrite(went_2, HIGH);


 lcd.begin(20, 4);



 //configure menu
 
 menu.getRoot().add(miTemperatura);
 miTemperatura.add(miT_zal).addRight(miT_wyl);
 miTemperatura.addRight(miWentylator1);
 menu.getRoot().add(miWentylator1);
 miWentylator1.add(miWen1_zal).addRight(miWen1_wyl);
 miWentylator1.addRight(miWentylator2);
 miWentylator2.add(miWen2_zal).addRight(miWen2_wyl);
 miWentylator2.addRight(miTemperatura);
 menu.toRoot();

}  // setup()...


void loop()
{
 readButtons();  //I splitted button reading and navigation in two procedures because
 navigateMenus();  //in some situations I want to use the button for other purpose (eg. to change some settings)

 czasidata();
 termometr();
}
byte bcdToDec(byte val)  {
 return ( (val / 16 * 10) + (val % 16) );
} //loop()...


void czasidata() {
 tmElements_t tm;
 if (RTC.read(tm)) {
   lcd.setCursor (0, 0);
   LCDprint2digits(tm.Hour);
   lcd.print(':');
   LCDprint2digits(tm.Minute);
   lcd.print(':');
   LCDprint2digits(tm.Second);
   lcd.setCursor (9, 0);
   lcd.print(tm.Day);
   lcd.print('/');
   lcd.print(monthName[tm.Month-1]);
   lcd.print('/');
   lcd.print(tmYearToCalendar(tm.Year));
 } else {
   if (RTC.chipPresent()) {
     lcd.println("DS1307 stoi. Uruchom Zegar");
     }
      else {
     lcd.println("DS1307 blad oczczytu!");
     lcd.println("sprawdz polaczenie");
   }
 }
}

void termometr() {
 sensors.requestTemperatures();
 float tempC1 = sensors.getTempC(P1);
 float tempC2 = sensors.getTempC(P2);
 
 lcd.setCursor(11, 1);
 lcd.print("Max ");
 lcd.print(temp);
 lcd.write(byte(223));
 lcd.setCursor (0, 1);
 lcd.print(tempC1, 2);
 lcd.write(byte(223));
 if (sensors.getTempCByIndex(0)+his_1 < (temp)) {
   his_1=0;
   digitalWrite(went_1, HIGH);
   int val = digitalRead(went_1);
   if (val)
     lcd.setCursor(7, 1);
   lcd.print("Wyl");
 } else {
   his_1=1;
   digitalWrite(went_1, LOW);
   lcd.setCursor(7, 1);
   lcd.print("Zal");
 }
}

void LCDprint2digits(int number) {
 if (number >= 0 && number < 10) {
   lcd.write('0');
 }
 lcd.print(number);
}


void menuChanged(MenuChangeEvent changed){
 
 MenuItem newMenuItem=changed.to; //get the destination menu
 
 lcd.setCursor(0,3); //set the start position for lcd printing to the second row
 
 if(newMenuItem.getName()==menu.getRoot()){
     lcd.print("Ustawienia       ");
 }else if(newMenuItem.getName()=="Temperatura"){
     lcd.print("Temperatura");
 }else if(newMenuItem.getName()=="T zal."){
     lcd.print("T zal.     ");
 }else if(newMenuItem.getName()=="T wyl."){
     lcd.print("T wyl.     ");
 }else if(newMenuItem.getName()=="Wentylator1"){
     lcd.print("Wentylator1");
 }else if(newMenuItem.getName()=="Wen1_zal"){
     lcd.print("Wen1_zal   ");
 }else if(newMenuItem.getName()=="Wen1_wyl"){
     lcd.print("Wen1_wyl   ");
 }else if(newMenuItem.getName()=="Wentylator2"){
     lcd.print("Wentylator2");
 }else if(newMenuItem.getName()=="Wen2_zal"){
     lcd.print("Wen2_zal   ");
 }else if(newMenuItem.getName()=="Wen2_wyl"){
     lcd.print("Wen2_wyl   ");
 }
}

void menuUsed(MenuUseEvent used){
 lcd.setCursor(0,3);  
 lcd.print("Wykonano        ");
 lcd.setCursor(10,3);
 lcd.print(used.item.getName());
 delay(3000);  //delay to allow message reading
 lcd.setCursor(10,3);  
 lcd.print("                ");
 lcd.setCursor(10,3);  
 lcd.print("                ");

 if(used.item.getName()=="T zal.")temp_zal(); // Temperatura zalaczenia

 menu.toRoot();  //back to Main
}


void  readButtons(){  //read buttons status
 int reading;
 int buttonEnterState=LOW;             // the current reading from the Enter input pin
 int buttonEscState=LOW;             // the current reading from the input pin
 int buttonLeftState=LOW;             // the current reading from the input pin
 int buttonRightState=LOW;             // the current reading from the input pin

 //Enter button
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinEnter);

                 // check to see if you just pressed the enter button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonEnterState) {
                   // reset the debouncing timer
                   lastEnterDebounceTime = millis();
                 }
                 
                 if ((millis() - lastEnterDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonEnterState=reading;
                   lastEnterDebounceTime=millis();
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonEnterState = reading;
                 

   //Esc button              
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinEsc);

                 // check to see if you just pressed the Down button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonEscState) {
                   // reset the debouncing timer
                   lastEscDebounceTime = millis();
                 }
                 
                 if ((millis() - lastEscDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonEscState = reading;
                   lastEscDebounceTime=millis();
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonEscState = reading;
                 
                   
  //Down button              
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinRight);

                 // check to see if you just pressed the Down button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonRightState) {
                   // reset the debouncing timer
                   lastRightDebounceTime = millis();
                 }
                 
                 if ((millis() - lastRightDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonRightState = reading;
                  lastRightDebounceTime =millis();
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonRightState = reading;                  
                 
                 
   //Up button              
                 // read the state of the switch into a local variable:
                 reading = digitalRead(buttonPinLeft);

                 // check to see if you just pressed the Down button
                 // (i.e. the input went from LOW to HIGH),  and you've waited
                 // long enough since the last press to ignore any noise:  
               
                 // If the switch changed, due to noise or pressing:
                 if (reading != lastButtonLeftState) {
                   // reset the debouncing timer
                   lastLeftDebounceTime = millis();
                 }
                 
                 if ((millis() - lastLeftDebounceTime) > debounceDelay) {
                   // whatever the reading is at, it's been there for longer
                   // than the debounce delay, so take it as the actual current state:
                   buttonLeftState = reading;
                   lastLeftDebounceTime=millis();;
                 }
                 
                 // save the reading.  Next time through the loop,
                 // it'll be the lastButtonState:
                 lastButtonLeftState = reading;  

                 //records which button has been pressed
                 if (buttonEnterState==HIGH){
                   lastButtonPushed=buttonPinEnter;

                 }else if(buttonEscState==HIGH){
                   lastButtonPushed=buttonPinEsc;

                 }else if(buttonRightState==HIGH){
                   lastButtonPushed=buttonPinRight;

                 }else if(buttonLeftState==HIGH){
                   lastButtonPushed=buttonPinLeft;

                 }else{
                   lastButtonPushed=0;
                 }
}

void navigateMenus() {
 MenuItem currentMenu=menu.getCurrent();

 switch (lastButtonPushed){
   case buttonPinEnter:
     if(!(currentMenu.moveDown())){  //if the current menu has a child and has been pressed enter then menu navigate to item below
       menu.use();
     }else{  //otherwise, if menu has no child and has been pressed enter the current menu is used
       menu.moveDown();
      }
     break;
   case buttonPinEsc:
     if(!(currentMenu.moveUp())){
       menu.toRoot();
     }else{
       menu.moveUp();
      }
     break;
   case buttonPinRight:
     menu.moveRight();
     break;
   case buttonPinLeft:
     menu.moveLeft();
     break;
 }
 lastButtonPushed=0; //reset the lastButtonPushed variable
}


void temp_zal()
      {
        lcd.setCursor(0,2);lcd.print("Ust.temp. = "); // tekst dla użytkownika
        lcd.setCursor(13,2);lcd.print(temp); // wyświetlamy akt. temperaturę

        int akcja=-1;delay(1000); // zmienna pomocnicza, sterująca dla petli while
                                           // jesli nie puścisz klawisza OK w ciągu 1 sek. to powrót do menu
        while(akcja!=buttonPinEnter) // ta pętla trwa tak długo aż wciśniesz klawisz OK
         {
           zm=-1;
           akcja=czytaj_1(0);//delay(300); // odczyt stanu klawiatury - funkcja czytaj_1 lub czytaj_2 lub czytaj_3
                                            // opis poniżej przy 3 różnych definicjach funkcji czytaj
           if(zm!=akcja) // ruszamy do pracy tylko wtedy gdy zmienił sie stan klawiatury
            {
             if (akcja==buttonPinRight) {temp++;if(temp>99)temp=99;lcd.setCursor(13,2);lcd.print(temp);delay(300);}
               // jesli akcja=1 (czyli wciśnieto klawisz w górę to zwiększono temperaturę
               // ustawiono max próg i wyświetlono obecną temperaturę
             if(akcja==buttonPinLeft) {temp--;if(temp<10)temp=10;lcd.setCursor(13,2);lcd.print(temp);delay(300);}
               // jesli akcja=2 (czyli wciśnięto klawisz w dół to mniejszono temperaturę
               // ustawiono min próg i wyświetlono obecną temperaturę
             if(akcja==buttonPinEnter) // jeśli wciśnieto OK
               {
                 lcd.setCursor(0,2);lcd.print("*Temperatura OK");delay(2000); // pokazujemy OK przez 2 sek.
               }
             }
           } zm=akcja;
         }

Pozdrawiam.
 
Odpowiedź
#2
a gdzie w pętli while masz odniesienie do zewnętrznego podprogramu sterowania klawiaturą ? Zapętlając program w while lub for musisz dać odniesienie do podprogramu który wpływa na funkcje zawarte w pętli . Coś w deseń poniżej

Kod:
   
    while(menu == 4){
 
    unsigned long Cm = millis();
   
   Przyciski(); // odwołanie do klawiatury przy ponownym rozpoczęciu pętli bez tego stan przycisku się nie zmieni i zawiśniesz w pętli
   
   if(MENU == LOW){menu = 0 ;break;} // przerwanie jak wyjdziemy z ustawień
 
   if (Cm - Pm > 200 ){ opóźnienie czasowe bez delay obsługi przycisków
   
switch (Przycisk) {

 case 4:   // przycisk 4
   timing++;
   break;
 case 3:    // przycisk 3
   timing--;
   break;
 case 2:
 

   break;
 case 1:  // przycisk 1 przejście do kolejnego podmenu
   menu = 5;
   break;
}      
 Pm = Cm; } zakończenie pętli czasowej do opóźnienia klawiatury
Ważne aby robić co się lubi albo lubić co się robi .
Arduino UNO, TINY, PRO MINI
Pomoc nagradzamy punktami reputacji Wink
 
Odpowiedź
#3
Nie ogarniam... Sad
 
Odpowiedź
#4
Która funkcja w pętli while odczytuje przyciski .
Ważne aby robić co się lubi albo lubić co się robi .
Arduino UNO, TINY, PRO MINI
Pomoc nagradzamy punktami reputacji Wink
 
Odpowiedź
#5
JasQ-u po raz kolejny to powiem, jesteś wielki! Poradziłem sobie dzięki Twoim radom, wystarczyło wrzucić po pętli loop:

Kod:
int czytaj()
{
int gora=3, lewo=7, ok=5, prawo=2, dol=4;
if(digitalRead(prawo)==HIGH)return 0;
if(digitalRead(gora)==HIGH)return 1;
if(digitalRead(dol)==HIGH)return 2;
if(digitalRead(lewo)==HIGH)return 3;
if(digitalRead(ok)==HIGH)return 4;
return -1;
}


i funkcja Wojtka działa idealnie! Dziękuje! Smile

Jeszcze jedno pytanie, na klawiszach podciągniętych rezystorami 1k i po zmianie sketch'u bez rezystorów na nano wszystko w obu wersjach działa idealnie, jednak gdy wrzucam owy sketch na identyczny układ na leonardzo i klawiaturę membranową, krzaczy się. Same przyciski wybierają jakieś opcje, podejrzewam, że jest to wina klawiatury, spotkał się ktoś z czymś takim?

Właśnie zamówiłem drugi egzemplarz identycznej klawiatury i jak tylko dojdzie, będę się bawił na układzie testowym, ale może do tego czas ktoś z Was rzuci jakąś sugestie. Wink

Pozdrawiam
 
Odpowiedź
#6
Niepotrzebnie klawiatura membranowa ma inny schemat połączeń , przycisk 1 to połączenie na taśmie to pin 1 i 4 chyba , poszukaj schematu w sieci bo w pracy jestem
Ważne aby robić co się lubi albo lubić co się robi .
Arduino UNO, TINY, PRO MINI
Pomoc nagradzamy punktami reputacji Wink
 
Odpowiedź
#7
Tylko to klawiatura z czterema przyciskami 1x4 i jest pięć przewodów, na 4 piny i masę. Już się bawię dalej, zmieniam odczyt klawiszy na ten z Wojtka SandBox'a. Zobaczymy, tyle już osiągnąłem, że byle klawiatura mnie nie pokona teraz. Wink

Tak na przyszłość, jest możliwość podpięcia tych 4 przycisków które teraz mam podpięte osobno pod piny cyfrowe pod jeden analogowy i sczytywanie ich częstotliwości, żeby zaoszczędzić piny cyfrowe?
 
Odpowiedź
#8
to nie wiem co może być z klawiaturą , tak możesz pod analoga dać ale z praktyki wiem że zacznie to pływać raczej prędzej niż później i tylko będziesz się denerwował .
Ważne aby robić co się lubi albo lubić co się robi .
Arduino UNO, TINY, PRO MINI
Pomoc nagradzamy punktami reputacji Wink
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości