• 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
Kalkulator kodów paskowych rezystora.
#1
Kod:
#include <LiquidCrystal.h>
 
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
//States for the menu.
int currentMenuItem = 0;
int lastState = 0;

//Wartości kolorów
int czarny=0;
int brazowy=1; 
int czerwony=2;
int pomaranczowy=3; 
int zolty=4;
int zielony=5; 
int niebieski=6;
int fioletowy=7; 
int szary=8;
int bialy=9; 

//Tolerancja w %
int brazowy1=1; 
int czerwony1=2;
int pomaranczowy1=15; 
int zielony1=0.5; 
int niebieski1=0.25;
int fioletowy1=0.1; 
int zloty=5;
int srebrny=10; 
int brak=20; 


int A = 0;// Dziesiątki
int B = 0;// Jedności
int C = 0;// Wynik  A+B
int D = 0;// Mnożnik
int E = 0;// Tolerancja
int F = 0;// Wynik C*D


void setup() {
   //Set the characters and column numbers.
   lcd.begin(16, 2);
   //Print default title.
   clearPrintTitle();
}
 
void loop() {
  //Call the main menu.
  mainMenu();
}
 
void mainMenu() {
  //State = 0 every loop cycle.
  int state = 0;
  //Refresh the button pressed.
  int x = analogRead (0);
  //Set the Row 0, Col 0 position.
  lcd.setCursor(0,0);
 
    if (x < 100) {
    //Right
  } else if (x < 200) {
   //Up
    state = 1;
  } else if (x < 400){
   //Down
    state = 2;
  } else if (x < 600){
    //Left
  } else if (x < 800){
    //Select
    state = 3;
  }
 
  //If we are out of bounds on th menu then reset it.
  if (currentMenuItem < 0 || currentMenuItem > 4) {
   currentMenuItem = 0; 
  }
 
      if (state != lastState) {
      if (state == 1) {
         //If Up
          currentMenuItem = currentMenuItem - 1; 
          displayMenu(currentMenuItem);
      } else if (state == 2) {
         //If Down
          currentMenuItem = currentMenuItem + 1;  
          displayMenu(currentMenuItem);
      } else if (state == 3) {
         //If Selected
         selectMenu(currentMenuItem); 
      }
            lastState = state;
   } 
   //Small delay
  delay(5);
}
 
void displayMenu(int x) {
     switch (x) {
      case 1:
        clearPrintTitle();
        lcd.print ("- KOD REZYSTOROW");
        lcd.setCursor(0,1);
        lcd.print ("                ");
        break;
      
    }

  }
void clearPrintTitle() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" * KALKULATOR *");
  lcd.setCursor(0,1);
  lcd.print(" * REZYSTOROW *");
  lcd.setCursor(0,0);
}
 
void selectMenu(int x) {
   switch (x) {
      case 1:
        clearPrintTitle();
        lcd.setCursor(0,0);
        lcd.print ("Pasek:          ");
        lcd.setCursor(0,1);
        lcd.print ("Kolor:          ");
        

  }
 }
Tyle zrobiłem. Zaciołem się na menu. Chcę przyciskiem selekt wybierać pasek a góra - dół kolor paska. Jak zrobić aby kursor przełączyć z górnej linii na dolną. Moduł Keypad shield. Po naciśnięciu down wyświetla mi kod rezystorów- selekt Pasek: i pod spodem Kolor:. Jak dodać podmenu do wyboru paska i koloru? Aby lewym wybierać pasek a prawym kolor?Nie wiem czy dobrze myślę. Pierwszy pasek-wartość koloru jako dziesiątki, drugi jako jednostki a trzeci jako mnożnik. Czwarty tolerancja. Np. Czerwony, czerwony,brązowy i złoty - wartość -x , a- dziesiątki , b-jedności,c-mnożnik,d-tolerancja czyli x=(a+b)*c  wartość = 22 x 10 , 5%- 220 om. x=>1000  to ?W przypadku gdy będzie 1500 to podzielić wynik przez 1000 aby było 1,5 Koma. Tylko jak to napisać? Pomocy !!!
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości