Advertisement
milanmetal

ARDUINO // Ispitni [Sreda 15:00]

Dec 13th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. // zadavanje pinova koji se koriste za komunikaciju s displejom
  3. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  4.  
  5. #define MAX 32
  6.  
  7. String in; // unos
  8. int wEn = true;
  9. int brCif[10];// = {0,0,0,0,0,0,0,0,0,0};
  10. String prviRed;
  11. String drugiRed;
  12.  
  13. bool bounceEn;
  14.  
  15. byte ocitaj_taster()
  16. {
  17.  int tmp = analogRead(0); //stanje tastera se ocitava preko
  18.  //analognog ulaza 0
  19.  if (tmp > 635 && tmp < 645) //SELECT
  20.  return 1;
  21.  if (tmp > 405 && tmp < 415) //LEFT
  22.  return 2;
  23.  if (tmp > 95 && tmp < 105) //UP
  24.  return 3;
  25.  if (tmp > 252 && tmp < 262) //DOWN
  26.  return 4;
  27.  if (tmp < 5) //RIGHT
  28.  return 5;
  29.  return 0; //nije pritisnut nijedan od tastera
  30. }
  31.  
  32.  
  33. void poruka(String msg){
  34.   Serial.println(msg);
  35.   }
  36.  
  37. void pauza(){
  38.     while(!Serial.available()){
  39.       // ne radi nita
  40.       }
  41.   }
  42.  
  43.   void unos(String &str){
  44.     pauza();
  45.     while(Serial.available()){
  46.       str = Serial.readString();
  47.       }
  48.     }
  49.  
  50. void setup() {
  51.   // put your setup code here, to run once:
  52.   Serial.begin(9600);
  53.  
  54.   lcd.begin(16,2);
  55.   lcd.setCursor(0,0);
  56. }
  57.  
  58. String prviRedStr(){
  59.    String ret;
  60.    for(int i = 0; i < 10; i++){
  61.        ret += String(i);
  62.     }
  63.     return ret;
  64. }
  65.  
  66.  
  67. String drugiRedStr(){
  68.    String ret;
  69.    for(int i = 0; i < 10; i++){
  70.        ret += String(brCif[i]);
  71.     }
  72.     return ret;
  73. }
  74.  
  75. void numericCnt(){
  76.   int aa;
  77.   String bb;
  78.   //poruka("Duzina" + String(in.length()));
  79.  
  80.     for(int i = 0; i < in.length(); i++){
  81.       if(isDigit(in[i])){
  82.         bb = String(in[i]);
  83.         aa++;
  84.         brCif[bb.toInt()]++;
  85.         }
  86.       }
  87.   }
  88.  
  89. void resetujNiz(){
  90.   for(int i = 0; i < 10; i++){
  91.     brCif[i] = 0;
  92.   }
  93. }
  94.  
  95. void test(){
  96.     for(int i = 0; i < 10; i++){
  97.       poruka("Broj " + String(i) + " je " + String(brCif[i]));
  98.     }
  99.   }
  100.  
  101. void loop() {
  102.   // put your main code here, to run repeatedly:
  103.  
  104.     if(wEn) {
  105.        //do {
  106.         resetujNiz();
  107.        
  108.         poruka("Unesite string  do 32 karaktera:");
  109.         unos(in);
  110.        // } while (in.length() > 32);
  111.        //poruka("Unesite string  do 32 karaktera:");
  112.        //unos(in);
  113.        while(in.length() > 32) {
  114.          poruka("Unesite PONOVO string  do 32 karaktera:");
  115.          unos(in);
  116.        }
  117.        
  118.        poruka("Uneli ste: " + in);
  119.        numericCnt();
  120.        
  121.        test();
  122.  
  123.        wEn = false;
  124.        
  125.     } else {
  126.  
  127.       prviRed = prviRedStr();
  128.       drugiRed = drugiRedStr();
  129.      
  130.       delay(150);
  131.  
  132.       int key = ocitaj_taster();
  133.  
  134.       if(key == 0){
  135.         bounceEn = true;  
  136.       }
  137.  
  138.       if(bounceEn){
  139.         if(key == 1){
  140.           prviRed = "Unesite string:";
  141.           drugiRed = " ";
  142.  
  143.           bounceEn = false;
  144.           wEn = true;
  145.         }
  146.       }
  147.      
  148.       lcd.clear();
  149.       lcd.setCursor(0,0);
  150.       lcd.print(prviRed);
  151.  
  152.       lcd.setCursor(0,1);
  153.       lcd.print(drugiRed);
  154.      
  155.     }
  156.    
  157.   //} while(in.length() >= 32);
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement