Gerard-Meier

Gerjo - IVIbot simple wall detection

Feb 19th, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. void main(void) {
  2.     unsigned int read;
  3.  
  4.     InitializeSystem();
  5.  
  6.     for(;;) {
  7.         read = getAD1();
  8.  
  9.         if(read > 150) { // No wall detected, move forwards!
  10.             PORTEbits.RE0 = 1;
  11.             PORTEbits.RE1 = 1;
  12.  
  13.             PORTB = 0b10001001;
  14.             CCPR2L = 128;
  15.             CCPR1L = 128;
  16.  
  17.         } else { // Wall detected, move backwards!
  18.             PORTEbits.RE0 = 0;
  19.             PORTEbits.RE1 = 0;
  20.  
  21.             PORTB = 0b00000001;
  22.             CCPR2L = 128;
  23.             CCPR1L = 128;
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment