Für den Schulunterricht habe ich diesen Quiz-Taster entwickelt. In seinem Inneren werkelt ein Arduino:
Das verwendete sketch ist sicher verbesserungswürdig, aber es tut seinen Dienst:
#include "pitches.h"
int Taster1 = 13;
int Lampe1 = 12;
int Taster2 = 7;
int Lampe2 = 6;
int myCounter1 = 0;
int myCounter2 = 0;
int myCounter3 = 0;
int myCounter4 = 0;
void setup() {
pinMode (Taster1, INPUT);
pinMode (Lampe1, OUTPUT);
pinMode (Taster2, INPUT);
pinMode (Lampe2, OUTPUT);
digitalWrite (Lampe1, HIGH);
delay (250);
digitalWrite (Lampe1, LOW);
digitalWrite (Lampe2, HIGH);
delay (250);
digitalWrite (Lampe2, LOW);
digitalWrite (Lampe1, HIGH);
delay (250);
digitalWrite (Lampe1, LOW);
digitalWrite (Lampe2, HIGH);
delay (250);
digitalWrite (Lampe2, LOW);
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
};
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; 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);
// 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() {
if (digitalRead (Taster1) == LOW)
{digitalWrite (Lampe1, LOW);
myCounter1 = 0;
myCounter4 = 0;}
if ((digitalRead (Taster1) == HIGH) && ((myCounter3) == 0))
{digitalWrite (Lampe1, HIGH);
if ((myCounter1) == 0) {tone (8, 300, 1000);}
myCounter1 = 1;
myCounter4 = 1;
delay (250);}
if (digitalRead (Taster2) == LOW)
{digitalWrite (Lampe2, LOW);
myCounter2 = 0;
myCounter3 = 0;}
if ((digitalRead (Taster2) == HIGH) && ((myCounter4) == 0))
{ digitalWrite (Lampe2, HIGH);
{if ((myCounter2) == 0) {tone (8, 600, 1000);}
myCounter2 = 1;
myCounter3 = 1;
delay (250);}
}}
[/code]
Keine Kommentare:
Kommentar veröffentlichen
Hinweis: Nur ein Mitglied dieses Blogs kann Kommentare posten.