diff --git a/docs/index.md b/docs/index.md index 88c937e..1905524 100644 --- a/docs/index.md +++ b/docs/index.md @@ -31,6 +31,7 @@ hide: 1. Don't forget the stamp !!! note annotate "7. Pianino (1)" + [Day 07](solutions/07/07.md) 1. Play me! !!! tip annotate "8. Will you get the lowest temperature? (1)" diff --git a/docs/solutions/05/05.md b/docs/solutions/05/05.md index bece8b0..86d7d96 100644 --- a/docs/solutions/05/05.md +++ b/docs/solutions/05/05.md @@ -1,4 +1,4 @@ -# Day four: +# Day five: Play a Christmas carol (or a song you like) using the Barduino. diff --git a/docs/solutions/07/07.md b/docs/solutions/07/07.md new file mode 100644 index 0000000..df01d81 --- /dev/null +++ b/docs/solutions/07/07.md @@ -0,0 +1,72 @@ +# Day seven: + +Make an instrument wit the Barduino. + +2 days ago you played some preprogrammed tunes, but now it's time to read some inputs and make sounds acording to them! Be creative, you can play with the different inputs... + +Here is my solution, playing notes with the touch pads reacting to light! I ave to practice a lot more... + +## Possible solution! + +### Arduino code + +```c++ +const int buzzer = 14; +int pressed = 0; + +const int photo = 3; +const int threshold = 27000; + +unsigned long values[] = {0,0,0,0}; +int playing = 0; + +note_t notes[] = {NOTE_C, NOTE_D, NOTE_E, NOTE_F, NOTE_G, NOTE_A, NOTE_B}; + +void setup() { + ledcAttachPin(buzzer, 1); + pinMode(photo, INPUT); + Serial.begin(115200); +} + +void loop() { + unsigned long max = 0; + int max_i; + for (int i=0; i<4; i++){ + values[i] = touchRead(i+4); + //Serial.println(values[i]); + if (values[i] > max){ + max = values[i]; + max_i = i; + } + } + if (max > threshold && playing != max_i + 4){ + playing = max_i + 4; + int val = map(analogRead(photo), 0, 4095, 0, 35); + //int val = 33; + Serial.println(val%7); + int note = val%7+max_i; + int oct = (val/7)+2; + if (note > 7){ + note = note - 7; + oct = oct + 1; + } + + Serial.print("Note: "); + Serial.print(note); + Serial.print(" Oct: "); + Serial.println(oct); + ledcWriteNote(1, notes[note], oct); + } + else if (max <= threshold && playing != 0){ + Serial.println("off"); + playing = 0; + ledcWriteTone(1, 0); + } +} +``` + +## Hero shot + + \ No newline at end of file diff --git a/docs/video/day07.mp4 b/docs/video/day07.mp4 new file mode 100644 index 0000000..ccac7a5 Binary files /dev/null and b/docs/video/day07.mp4 differ diff --git a/mkdocs.yml b/mkdocs.yml index 7a66a2c..331f8ac 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -19,6 +19,7 @@ nav: - Day 4: solutions/04/04.md - Day 5: solutions/05/05.md - Day 6: solutions/06/06.md + - Day 7: solutions/07/07.md - Solution template: - template.md