Advertisement
justhrun

Arduino_FlasherSpedaMotor_Attiny13

Jul 11th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. /*
  2. ATTINY13
  3.  +Vcc-----------1-|    |-8--Vcc
  4.   PB3 = IN_PIN--2-|    |-7--NC
  5.   PB4 = BUZZER--3-|    |-6--OUT_PIN = PB1
  6.            Gnd--4-|    |-5--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   PB3
  15. #define   OUTPIN   PB1
  16. #define   BUZPIN   PB4
  17. #define  IN_HIGH  (PINB & (1<<INPIN)) != 0
  18.  
  19. unsigned long waitPoint=0;
  20. const uint16_t max_on = 65535;
  21.  
  22. void setup() {                
  23.  
  24.   DDRB &=~(1 << INPIN); // input
  25.   DDRB |= (1 << OUTPIN); // output
  26.   DDRB |= (1 << BUZPIN); // output
  27.  
  28.   _beep(2);
  29.   if(IN_HIGH) {
  30.     waitPoint = millis();
  31.   } else {
  32.     PORTB |=  (1<<BUZPIN); delay(1500);
  33.     PORTB &= ~(1<<BUZPIN);
  34.     waitPoint = millis() - 50000;
  35.   }
  36. }
  37.  
  38. void loop() {
  39.   while(!IN_HIGH && (millis() - waitPoint) < max_on ) kedip();
  40.   tunggu(IN_HIGH);
  41.   _beep(1);
  42.   waitPoint = millis();
  43. };
  44.  
  45. void tunggu(uint16_t x) {
  46.   if(!x) { // kalo timeout msh on
  47. //    _beep(1);
  48.     PORTB |=  (1<<BUZPIN); delay(1500);
  49.     PORTB &= ~(1<<BUZPIN);
  50.   }
  51.   // masih off/on
  52.   while(IN_HIGH==x) delay(200);
  53. };
  54.  
  55. void kedip(void) {
  56.   PORTB |=  (1<<OUTPIN); delay(550);
  57.   PORTB &= ~(1<<OUTPIN); delay(500);
  58.  
  59.   PORTB |=  (1<<OUTPIN); delay(350);
  60.   PORTB &= ~(1<<OUTPIN); delay(350);
  61.  
  62.   PORTB |=  (1<<OUTPIN); delay(350);
  63.   PORTB &= ~(1<<OUTPIN); delay(550);
  64. };
  65.  
  66. void _beep(byte x) {
  67.   for(byte i=0;i<x;i++) {
  68.     PORTB |=  (1<<BUZPIN); delay(250);
  69.     PORTB &= ~(1<<BUZPIN); delay(200);
  70.   }
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement