Advertisement
losmi93

REKLAMA nedovrsem, trebaju da se ispreve mod unosa i prikaza

Dec 6th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd (8, 9, 4, 5, 6, 7);
  3.  
  4. int analogPin = 0;
  5. int val = 0;
  6.  
  7. void setup ()
  8. {
  9.   Serial.begin (9600) ;
  10.   lcd.begin(16, 2);
  11.   lcd.setCursor(0,0);
  12.   lcd.cursor();
  13.   lcd.noBlink();
  14.  
  15. }
  16.  
  17. int procitajTaster(int val) {
  18.   if (val > 620 && val < 660)return 1;
  19.   else if (val > 390 && val < 430)return 2;
  20.   else if (val > 80 && val < 120)return 3;
  21.   else if (val > 245 && val < 275)return 4;
  22.   else if ( val < 20 && val > -20)return 5;
  23.   else return 0;
  24.  
  25. }
  26.  
  27. char currChar = 'A';
  28. int trenutniPolozajSlova = 0;
  29. int prosliPolozaj = 0;
  30.  
  31. int modUpisa(int stanje){
  32.  
  33.  switch(stanje){
  34.   case 1:if(prosliPolozaj == 0)return 1;
  35.   prosliPolozaj = 1;
  36.   break;
  37.   case 2:if(prosliPolozaj == 0){trenutniPolozajSlova--; currChar = '@';}
  38.    prosliPolozaj = 2;
  39.   break;
  40.   case 3:if(prosliPolozaj == 0){if(currChar == '@'){lcd.print(' ');currChar++;}else {lcd.print(currChar);currChar++;}}
  41.    prosliPolozaj = 3;
  42.   break;
  43.   case 4:if(prosliPolozaj == 0){if(currChar == '@'){lcd.print(' ');currChar--;}else {lcd.print(currChar);currChar--;}}
  44.    prosliPolozaj = 4;
  45.   break;  
  46.   case 5:if(prosliPolozaj == 0){trenutniPolozajSlova++; currChar = '@';}
  47.    prosliPolozaj = 5;
  48.   break;  
  49.   default:
  50.   prosliPolozaj = 0;
  51.   }
  52.   lcd.setCursor(trenutniPolozajSlova,0);
  53.  
  54.  
  55. return 0;  }
  56.  
  57.  
  58. int pomeranjeDispleja = 0;
  59. int iteracija = 0;
  60.  
  61. int modPrezentacije(int stanje){
  62.  lcd.noCursor();
  63.  if(pomeranjeDispleja == 0){if(!(iteracija%20))lcd.scrollDisplayLeft();iteracija++;if(iteracija==140)pomeranjeDispleja = 1;}
  64.  else {if(!(iteracija%20))lcd.scrollDisplayRight();iteracija--;if(iteracija==-140)pomeranjeDispleja = 0;}
  65.  delay(15);
  66. }
  67.  
  68.  
  69. int mod = 0;
  70. void loop ()
  71. {
  72. lcd.print(currChar);
  73.  
  74. while(1){
  75.   val = analogRead ( analogPin ); // ocitava analogni ulaz pin
  76.  
  77.   if(mod == 0){if(1==modUpisa(procitajTaster(val)))mod =1;}
  78.   else modPrezentacije(procitajTaster(val));
  79.  
  80.  
  81. delay(20);
  82. Serial.println( mod);
  83. }
  84.  
  85.  
  86.  
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement