Advertisement
sunu

simple sample arduino shift left bit

Oct 13th, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. LiquidCrystal lcd(8,9,4,5,6,7);
  4.  
  5. //kode modifikasi dari kode:credits to mem
  6. //http://forum.arduino.cc/index.php/topic,46320.0.html
  7. void printBits(byte lcdCol, byte lcdRow, byte myByte){
  8.   lcd.setCursor(lcdCol,lcdRow);
  9.   for(byte mask = 0x80; mask; mask >>= 1){
  10.     if(mask  & myByte)
  11.         lcd.print('1');
  12.     else
  13.         lcd.print('0');
  14.   }
  15. }
  16.  
  17.  
  18. void setup(void)
  19. {
  20.   //
  21.   lcd.begin(16,2);
  22.   lcd.clear();
  23.   lcd.print("Mulai");
  24.   delay(600);
  25.  
  26.   int varA = 0b00100001;
  27.   lcd.clear();
  28.   //lcd.print(varA,BIN);
  29.   printBits(0,0,varA);
  30.  
  31.   //delay(5);
  32.  
  33.   //varA <<= 3;
  34.  
  35.   //lcd.setCursor(0,1);
  36.   //lcd.print(varA,BIN);
  37.   //printBits(0,1,varA);
  38.   //delay(2000);  
  39.  
  40. }
  41.  
  42.  
  43. void loop(void)
  44. {
  45.   //
  46.   byte varB = 0b00100001;
  47.   byte i=0;
  48.  
  49.  
  50.   //lcd.clear();
  51.   //lcd.setCursor(0,1);
  52.   //lcd.print("               ");
  53.  
  54.  
  55.   for(i;i<10;i++)
  56.   {
  57.     lcd.setCursor(14,1);
  58.     lcd.print(i);
  59.     //lcd.setCursor(0,1);
  60.    
  61.     printBits(0,1,varB);
  62.     varB<<=1;
  63.     delay(3000);
  64.    
  65.  
  66.    
  67.   }  
  68.   delay(1000);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement