Advertisement
losmi93

REKLAMA-FINAL

Dec 7th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.52 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd (8, 9, 4, 5, 6, 7);
  3.  
  4. void setup ()
  5. {
  6.   Serial.begin (9600) ;
  7.   lcd.begin(16, 2);
  8.   lcd.setCursor(0,0);
  9.   lcd.cursor();
  10.   lcd.noBlink();
  11. }
  12.  
  13. int procitajTaster(int val) {
  14.   if (val > 620 && val < 660)return 1;
  15.   else if (val > 390 && val < 430)return 2;
  16.   else if (val > 80 && val < 120)return 3;
  17.   else if (val > 245 && val < 275)return 4;
  18.   else if ( val < 20 && val > -20)return 5;
  19.   else return 0;
  20. }
  21.  
  22.  static int prosloStanje = 0;
  23.  
  24. int modUpisa(int stanje){
  25.  
  26.   lcd.cursor();
  27.  
  28. static char currChar = 'A';
  29. static int trenutniPolozajSlova = 0;
  30.  
  31.  
  32.  switch(stanje){
  33.   case 1:
  34.   prosloStanje = 1;
  35.  
  36.   break;
  37.   case 2:
  38.   if(prosloStanje == 0){
  39.     trenutniPolozajSlova--; currChar = '@';
  40.     }prosloStanje = 2;
  41.    
  42.   break;
  43.   case 3:
  44.   if(prosloStanje == 0){
  45.     if(currChar == '@'){
  46.       lcd.print(' ');currChar++;
  47.       }else {lcd.print(currChar);currChar++;}
  48.       } prosloStanje = 3;
  49.  
  50.   break;
  51.   case 4:
  52.   if(prosloStanje == 0){
  53.     if(currChar == '@'){
  54.       lcd.print(' ');currChar--;}
  55.       else {
  56.         lcd.print(currChar);
  57.         currChar--;}
  58.         } prosloStanje = 4;
  59.  
  60.  
  61.   break;  
  62.   case 5:
  63.   if(prosloStanje == 0){
  64.     trenutniPolozajSlova++; currChar = '@';
  65.     }prosloStanje = 5;
  66.    
  67.   break;  
  68.   default:  prosloStanje = 0;
  69.   }
  70.  
  71.   if(trenutniPolozajSlova < 0)trenutniPolozajSlova = 32;
  72.   if(trenutniPolozajSlova > 32)trenutniPolozajSlova = 0;
  73.  
  74.   if(trenutniPolozajSlova < 16)lcd.setCursor(trenutniPolozajSlova,0);
  75.   else lcd.setCursor(trenutniPolozajSlova - 16 ,2);
  76.  
  77.  delay(20);
  78.   return 0;  
  79.   }
  80.  
  81. void modPrezentacije(){
  82.  
  83. static int pomeranjeDispleja = 0; //0 levo, 1 desno
  84. static int iteracija = 0;
  85.  
  86.  
  87.  
  88.  lcd.noCursor();
  89.  if(pomeranjeDispleja == 0){
  90.   if(!(iteracija%20))lcd.scrollDisplayLeft();
  91.   iteracija++;
  92.   if(iteracija==100)pomeranjeDispleja = 1;
  93.   }
  94.  else {
  95.   if(!(iteracija%20))lcd.scrollDisplayRight();
  96.   iteracija--;
  97.   if(iteracija==-100)pomeranjeDispleja = 0;
  98.   }
  99.  delay(20);
  100. }
  101.  
  102. void loop (){
  103.  
  104.           static int mod = 0; // 0 -> mod upisa, 1-> pod prezentacije;
  105.           static int taster = 0;
  106.          
  107.           while(1){
  108.            
  109.           taster = procitajTaster( analogRead(0) );
  110.          
  111.            if (taster != prosloStanje){
  112.             if(taster == 1)mod = !mod;
  113.           }
  114.          
  115.           //modUpisa( taster );
  116.          
  117.           if(mod == 0)modUpisa( taster );
  118.           else {modPrezentacije();  prosloStanje = taster;}
  119.  
  120.  
  121.  
  122.  
  123.  }
  124.  
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement