Advertisement
justhrun

Arduino_FlasherSpedaMotor_Attiny85

Jul 11th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. /*
  2. ATTINY13/85
  3.  +Vcc-----------1-|    |-8--Vcc
  4.       NC - PB3--2-|    |-7--PB2 = BUZZER
  5.  OUT_PIN = PB4--3-|    |-6--PB1 = IN_PIN
  6.            Gnd--4-|    |-5--PB0 - NC
  7.            
  8. (PCINT5/RESET/ADC0/dW) PB5---1-|    |-8---VCC
  9.     (PCINT3/CLKI/ADC3) PB3---2-|    |-7---PB2 (SCK/ADC1/T0/PCINT2)
  10.          (PCINT4/ADC2) PB4---3-|    |-6---PB1 (MISO/AIN1/OC0B/INT0/PCINT1)
  11.                        GND---4-|    |-5---PB0 (MOSI/AIN0/OC0A/PCINT0)
  12. */
  13.  
  14. #define    INPIN   PB1
  15. #define   OUTPIN   PB4
  16. #define   BUZPIN   PB2
  17.  
  18. #define  IN_HIGH  (PINB & (1<<INPIN))
  19. #define   NYALA      PORTB |=  (1<<OUTPIN)
  20. #define   MATI       PORTB &= ~(1<<OUTPIN)
  21.  
  22. unsigned long waitPoint=0;
  23. const unsigned long max_on = 65535;
  24.  
  25. void setup() {                
  26.  
  27.   DDRB &=~(1 << INPIN); // input
  28.   DDRB |= (1 << OUTPIN); // output
  29.   DDRB |= (1 << BUZPIN); // output
  30.   MATI;
  31.   _beep(2);
  32.   if(IN_HIGH) {
  33.     waitPoint = millis();
  34.   } else {
  35.     PORTB |=  (1<<BUZPIN); delay(500);
  36.     PORTB &= ~(1<<BUZPIN);
  37.     waitPoint = millis() - 50000;
  38.   }
  39. }
  40.  
  41. void loop() {
  42.   while(!IN_HIGH && (millis() - waitPoint) < max_on ) kedip();
  43.   tunggu(IN_HIGH);
  44.   waitPoint = millis();
  45. };
  46.  
  47. void tunggu(byte x) {
  48.   byte old_x = x;
  49.   if(!x) { // kalo timeout msh on
  50.     PORTB |=  (1<<BUZPIN); delay(500);
  51.     PORTB &= ~(1<<BUZPIN);
  52.   }
  53.   // masih off/on
  54.   while(IN_HIGH==x) delay(200);
  55.   if(old_x) _beep(1);
  56. };
  57.  
  58. void kedip(void) {
  59.   NYALA; delay(500);
  60.   MATI ; delay(450);
  61.  
  62.   NYALA; delay(350);
  63.   MATI ; delay(350);
  64.  
  65.   NYALA; delay(350);
  66.   MATI ; delay(450);
  67. };
  68.  
  69. void _beep(byte x) {
  70.   for(byte i=0;i<x;i++) {
  71.     PORTB |=  (1<<BUZPIN); delay(75);
  72.     PORTB &= ~(1<<BUZPIN); delay(75);
  73.   }
  74. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement