ahmedtarek97 / ASUMobiCarG66

5 stars 6 forks source link

Any help in Problem 1 in sheet 2 #6

Closed ahmdshrf closed 6 years ago

EL-SHREIF commented 6 years ago

//avr code for this problem

define F_CPU 16000000

include <avr/io.h>

include <util/delay.h>

include <avr/interrupt.h>

void hi(int t) { int i=1; for(i=1;i<=t;i++) { _delay_ms(40); } return 0; }

int main (void){ DDRC=0x03; DDRA=0x00; PORTA=0b11111111; int x,y;

while (1)
{
  x=PINA;
  y=1;
  PORTC=0b00000001;
  hi(x);
  PORTC=0b00000010;
  while(y==1)
  {
  if(PINA==x)
  {
  y=1;
  }
  else
  {
  y=0;
  }
  }
}

    return 0;

}

Ahmdnsr commented 6 years ago

int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 };

int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 };

void setup() {

for (int thisNote = 0; thisNote < 8; thisNote++) {

. int noteDuration = 1000 / noteDurations[thisNote]; tone(8, melody[thisNote], noteDuration);

int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);

noTone(8);

} }

void loop() {

}

Ahmdnsr commented 6 years ago

//arduino is using in this prob

define NOTE_C4 262

define NOTE_G3 196

define NOTE_A3 220

define NOTE_B3 247

define NOTE_C4 262

// notes in the melody: int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 };

// note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 };

void setup() { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 8; thisNote++) {

int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);

int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);

noTone(8);

} }

void loop() { // no need to repeat the melody. }