Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2024:vstoica:cosmin.temciuc [2024/05/05 16:33]
cosmin.temciuc
pm:prj2024:vstoica:cosmin.temciuc [2024/05/26 11:53] (current)
cosmin.temciuc
Line 15: Line 15:
  
   * Fire si rezistoare: Folosite pentru trecerea curentului prin componente, si protejarea acestora ​   * Fire si rezistoare: Folosite pentru trecerea curentului prin componente, si protejarea acestora ​
 +
 +  * Led RGB: Folosit pentru a reprezenta octava la care pianul canta la momentul curent
  
 ===== Hardware Design ===== ===== Hardware Design =====
  
   * 10 butoane   * 10 butoane
-  * 10 1k resistori+  * 13 1k resistori
   * Fire   * Fire
   * Buzzer activ 5V Rasberry OKY0151   * Buzzer activ 5V Rasberry OKY0151
   * Arduino Uno R3   * Arduino Uno R3
 +  * Led RGB
  
-{{:​pm:​prj2024:​screenshot_2024-05-04_221258.png?300|}}+{{:​pm:​prj2024:​vstoica:​pian.png?400|}}
 ===== Software Design ===== ===== Software Design =====
  
Line 36: Line 39:
 </​note>​ </​note>​
  
 +Mediul de dezvoltare:
 +
 +  * Codul a fost scris in Arduino IDE.
 +  * Schema electrica a fost realizata in Tinkercad
 +
 +**Functia setup** : Initializeaza pinii digitali si pe cei de intrerupere:​
 +<​note>​
 +  Serial.begin(9600);​
 +  // SETEAZA PINUL 5 CA OUTPUT (BUZZER)
 +  DDRD |= (1 << DDD5);
 +  // SETEAZA PINUL 4 CA OUTPUT (LED)
 +  DDRD |= (1 << DDD4);
 +  // SETEAZA PINUL 6 SI 7 CA INPUS
 +  DDRD &= ~((1 << DDD6) | (1 << DDD7));
 +  PORTD |= ((1 << PORTD6) | (1 << PORTD7));
 +  // SETEAZA PINUL 8-13 CA INPUS
 +  DDRB &= ~((1 << DDB0) | (1 << DDB1) | (1 << DDB2) | (1 << DDB3) | (1 << DDB4) | (1 << DDB5));
 +  PORTB |= ((1 << PORTB0) | (1 << PORTB1) | (1 << PORTB2) | (1 << PORTB3) | (1 << PORTB4) | (1 << PORTB5));
 +  // SETEAZA PINUL 2 SI 3 CA INPUT PENTRU INTRERUPERI
 +  DDRD &= ~((1 << DDD2) | (1 << DDD3));
 +  PORTD |= ((1 << PORTD2) | (1 << PORTD3));
 +  // CONFIGURARE INTRERUPERI
 +  EICRA |= (1 << ISC01); // PD2
 +  EICRA |= (1 << ISC11); // PD3
 +  EIMSK |= (1 << INT0) | (1 << INT1); //ACTIVAM INTRERUPERILE
 +  sei();
 +</​note>​
 +
 +**Functia loop** : Verifica daca s-a apasat vreo clapa, si face reprezentarea unei octave, in cazul schimbarii acesteia
 +<​note>​
 +    if (octave >= 0 && octave <= 2) {
 +    if (!(PINB & (1 << PINB5))) {
 +      tone(5, f0[octave * 8], 100); // PINUL 13
 +      Serial.println("​btn1 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +    if (!(PINB & (1 << PINB4))) {
 +      tone(5, f0[octave * 8 + 1], 100); // PINUL 12
 +      Serial.println("​btn2 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +
 +    if (!(PINB & (1 << PINB3))) {
 +      tone(5, f0[octave * 8 + 2], 100); // PINUL 11
 +      Serial.println("​btn3 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +    if (!(PINB & (1 << PINB2))) {
 +      tone(5, f0[octave * 8 + 3], 100); // PINUL 10
 +      Serial.println("​btn4 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +    if (!(PINB & (1 << PINB1))) {
 +      tone(5, f0[octave * 8 + 4], 100); // PINUL 9
 +      Serial.println("​btn5 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +    if (!(PINB & (1 << PINB0))) {
 +      tone(5, f0[octave * 8 + 5], 100); // PINUL 8
 +      Serial.println("​btn6 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +    if (!(PIND & (1 << PIND7))) {
 +      tone(5, f0[octave * 8 + 6], 100); // PINUL 7
 +      Serial.println("​btn7 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +    if (!(PIND & (1 << PIND6))) {
 +      tone(5, f0[octave * 8 + 7], 100); // PINUL 6
 +      Serial.println("​btn8 apasat."​);​
 +      _delay_ms(100);​
 +    }
 +    //​REPREZENTARE OCTAVA
 +    if(state == true){
 +      if(octave == 0){
 +        PORTD |= (1 << PORTD4); //APRINDEM LEDUL
 +        _delay_ms(100);​
 +        PORTD &= ~(1 << PORTD4); //STINGEM LEDUL
 +      }
 +      else if (octave == 1){
 +        PORTD |= (1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD &= ~(1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD |= (1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD &= ~(1 << PORTD4);
 +      }
 +      else if (octave == 2){
 +        PORTD |= (1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD &= ~(1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD |= (1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD &= ~(1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD |= (1 << PORTD4);
 +        _delay_ms(100);​
 +        PORTD &= ~(1 << PORTD4);
 +      }
 +      Serial.println(octave);​
 +      state = false;
 +    }
 +  }
 +  _delay_ms(10);​
 +</​note>​
 +
 +**Intreruperile** : Acestea sunt realizate pe butoanele ce schimba octavele, avand rolul de a creste performanta codului.
 +<​note>​
 +  ISR(INT0_vect) {
 +  unsigned long currentTime = millis();
 +  if (currentTime - lastDebounceTimeUp > debounceDelay) {
 +  octaveUp();
 +  lastDebounceTimeUp = currentTime;​
 +  }
 +  }
 +  ISR(INT1_vect) {
 +  unsigned long currentTime = millis();
 +  if (currentTime - lastDebounceTimeDown > debounceDelay) {
 +    octaveDown();​
 +    lastDebounceTimeDown = currentTime;​
 +  }
 +  }
 +  void octaveDown(void) {
 +  Serial.println("​Interrupt for Octave Down triggered"​);​
 +  octave = max(0, octave - 1);
 +  Serial.println("​OCT1 apasat."​);​
 +  state = true;
 +  _delay_ms(200);​
 +  }
 +  void octaveUp(void) {
 +  Serial.println("​Interrupt for Octave Up triggered"​);​
 +  octave = min(2, octave + 1);
 +  Serial.println("​OCT2 apasat."​);​
 +  state = true;
 +  _delay_ms(200);​
 +  }
 +</​note>​
 ===== Rezultate Obţinute ===== ===== Rezultate Obţinute =====
  
pm/prj2024/vstoica/cosmin.temciuc.1714916017.txt.gz · Last modified: 2024/05/05 16:33 by cosmin.temciuc
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0