Advertisement
Moortiii

Arduino Hand in 3

Feb 5th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #define BTN   (1 << 1)
  2. #define LED_1 (1 << 2)
  3. #define LED_2 (1 << 3)
  4. #define LED_3 (1 << 4)
  5. #define PIN_LEDS (LED_1 | LED_2 | LED_3)
  6.  
  7. void setup()
  8. {
  9.   // Set up our serial monitor
  10.   Serial.begin(9600);
  11.  
  12.   // Set our LEDs as output
  13.   DDRB |= PIN_LEDS;
  14.  
  15.   // Set our BTN as input
  16.   DDRB &= BTN;
  17.  
  18.   // Set our button as internal pullup
  19.   PORTB |= BTN;
  20. }
  21.  
  22. void loop()
  23. {
  24.   int val = analogRead(A0);
  25.   Serial.println(val);
  26.  
  27.   if(!(PINB & BTN)) {
  28.     PORTB |= LED_1;
  29.     delay(val);
  30.    
  31.     PORTB |= LED_2;
  32.     delay(val);
  33.    
  34.     PORTB |= LED_3;
  35.     delay(val);
  36.    
  37.     PORTB &= ~LED_3;
  38.     delay(val);
  39.    
  40.     PORTB &= ~LED_2;
  41.     delay(val);
  42.    
  43.     PORTB &= ~LED_1;
  44.     delay(val);
  45.    
  46.   } else {
  47.     PINB &= ~PIN_LEDS;
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement