myGully.com

myGully.com (https://mygully.com/index.php)
-   Programmierung (https://mygully.com/forumdisplay.php?f=67)
-   -   Arduino uno programmierproblem (https://mygully.com/showthread.php?t=2491595)

GayFish 21.11.11 23:16

Arduino uno programmierproblem
 
hallo
war am Wochenende auf einem Arduino Workshop und bin gerade dabei ein bisschen rumzuspielen mit dem ding bin auch noch ein ziemlicher anfänger in dem bereich habe vor "alle meine Entchen" über einen Lautsprecher abzuspielen das klappt auch soweit zusätzlich habe ich noch 7 LEDs auf meinem steckboard aufgebaut und ich möchte jetz jeder LED einen Ton zuordnen habe aber immer ein fehler beim Compiling
es wird mir keine Zeile markiert
hier das Programm:

Zitat:

#include "pitches.h"

// notes in the melody:
int melody[] = {
NOTE_C2, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_A3,
NOTE_A3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_A3, NOTE_A3, NOTE_A3, NOTE_G3,
NOTE_F3, NOTE_F3, NOTE_F3, NOTE_F3, NOTE_E3, NOTE_E3, NOTE_D3, NOTE_D3,
NOTE_D3, NOTE_D3, NOTE_C3};

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

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


// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
if (melody[thisNote] == NOTE_C2) digitalWrite(2, HIGH);
if (melody[thisNote] == NOTE_D3) digitalWrite(3, HIGH);
if (melody[thisNote] == NOTE_E3) digitalWrite(4, HIGH);
if (melody[thisNote] == NOTE_F3) digitalWrite(5, HIGH);
if (melody[thisNote] == NOTE_G3) digitalWrite(6, HIGH);
if (melody[thisNote] == NOTE_A3) digitalWrite(7, HIGH);
if (melody[thisNote] == NOTE_C3) digitalWrite(8, HIGH);

// if (x > 120) digitalWrite(LEDpin, HIGH);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}

void loop() {
// no need to repeat the melody.
}
ich weiß nicht was ich falsch mache ich würd mich über hilfe freuen

MFG GayFish

GayFish 22.11.11 11:21

hallo
ein bekannter hat mir geholfen wenns jemand interessiert hier ist das fehlerfreie programm
ich hatte die Pin declaration vergessen und noch ein paar andere kleine fehler gemacht
Zitat:

#include "pitches.h"

// notes in the melody:
int melody[] = {
NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_A3,
NOTE_A3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_A3, NOTE_A3, NOTE_A3, NOTE_G3,
NOTE_F3, NOTE_F3, NOTE_F3, NOTE_F3, NOTE_E3, NOTE_E3, NOTE_D3, NOTE_D3,
NOTE_D3, NOTE_D3, NOTE_C3};

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

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 27; thisNote++) {


// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
if(melody[thisNote] == NOTE_C3) {
digitalWrite(2, HIGH);
}
if(melody[thisNote] == NOTE_D3) {
digitalWrite(3, HIGH);
}
if(melody[thisNote] == NOTE_E3) {
digitalWrite(4, HIGH);
}
if(melody[thisNote] == NOTE_F3) {
digitalWrite(5, HIGH);
}
if(melody[thisNote] == NOTE_G3) {
digitalWrite(6, HIGH);
}
if(melody[thisNote] == NOTE_A3) {
digitalWrite(7, HIGH);
}
// if (x > 120) digitalWrite(LEDpin, HIGH);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
// stop the tone playing:
noTone(8);
}
}

void loop() {
// no need to repeat the melody.
}
jetz wird alle meine entchen abgespielt und immer wenn ein anderer Ton kommt geht eine andere LED an natürlich schön in rheinfolge auf gebaut

MFG GayFish

GayFish 22.11.11 19:15

Hier ein Video von dem ganzen

[Link nur für registrierte und freigeschaltete Mitglieder sichtbar. Jetzt registrieren...]

Freezzers 06.02.13 22:10

kleiner Tipp:
[Link nur für registrierte und freigeschaltete Mitglieder sichtbar. Jetzt registrieren...]
es gibt auch eine "deutsch Ecke"


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:59 Uhr.

Powered by vBulletin® (Deutsch)
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.