Zorbing

[ES] Wasserdrucksensor.c

Jul 24th, 2014
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. void main() {
  2.     adc_init();
  3.     DDRA &= ~((1 << PA0) | (1 << PA1));
  4.     DDRB |= (1 << PB0);
  5.     while (1) {
  6.         uint16_t counter = 50000;
  7.         uint8_t refBit = 3;
  8.         while (counter > 0) {
  9.             counter--;
  10.             refBit &= 1 + ((PINA & (1 << PA1)) >> 1);
  11.             delay(39);
  12.         }
  13.         // is the refBit 1 or 2? => maskBit is 1 else 0
  14.         uint8_t maskBit = (refBit & 1 | (refBit >> 1) & 1);
  15.         PORTB = PORTB & ~(maskBit << PB0);
  16.  
  17.         uint16_t strangeWaterLevelValue = get_adc();
  18.         if (strangeWaterLevelValue < 100)
  19.             PORTB = PORTB & ~(1 << PB0);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment