|
|
# Ausgangslage
|
|
|
* Ereignisse haben Audio-Effekte
|
|
|
* Bumber, Flips, etc.
|
|
|
|
|
|
# Bedingungen
|
|
|
* sinvolle Datentypen verwenden
|
|
|
|
|
|
# Aufbau
|
|
|
* [Seeeduino V4.2](http://wiki.seeed.cc/Seeeduino_v4.2)
|
|
|
* als [**Arduino UNO**](https://www.arduino.cc/en/Main/Software) programmieren
|
|
|
* **nicht** den "Driver for Seeeduino V4.2" installieren
|
|
|
* Input
|
|
|
* [Wii Nunchuck](http://wiki.seeed.cc/Grove-NunChuck)
|
|
|
* Output
|
|
|
* [Speaker](http://wiki.seeed.cc/Grove-Speaker) für die Audio-Effekte
|
|
|
* als digiteler Output <code>#define SPEAKER 3</code> ansteuerbar
|
|
|
|
|
|
# Handlungsziele
|
|
|
|
|
|
|Vorgehen|Hannok [Handlungsnotwendige Kenntnisse](https://cf.ict-berufsbildung.ch/modules.php?name=Mbk&a=20101&cmodnr=242&noheader=1)|
|
|
|
|:-------|:------|
|
|
|
|unterschiedliche Töne / Frequenzen erzeugen | Array |
|
|
|
|Testbarkeit | Loggen, UART |
|
|
|
|
|
|
|
|
|
# CodeSample
|
|
|
```c
|
|
|
#define SPEAKER 3
|
|
|
|
|
|
int BassTab[] = {1911, 1702, 1516, 1431, 1275, 1136, 1012}; // bass 1~7
|
|
|
|
|
|
void setup() {
|
|
|
pinMode(SPEAKER, OUTPUT);
|
|
|
digitalWrite(SPEAKER, LOW);
|
|
|
}
|
|
|
|
|
|
void loop() {
|
|
|
for (int note_index = 0; note_index < 7; note_index++) {
|
|
|
sound(note_index);
|
|
|
delay(50);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void sound(uint8_t note_index) {
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
digitalWrite(SPEAKER, HIGH);
|
|
|
delayMicroseconds(BassTab[note_index]);
|
|
|
digitalWrite(SPEAKER, LOW);
|
|
|
delayMicroseconds(BassTab[note_index]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|