Skip to content

Commit

Permalink
day07
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepMartiElias committed Dec 7, 2023
1 parent 16af4c9 commit 7c203be
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion docs/solutions/05/05.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Day four:
# Day five:

Play a Christmas carol (or a song you like) using the Barduino.

Expand Down
72 changes: 72 additions & 0 deletions docs/solutions/07/07.md
Original file line number Diff line number Diff line change
@@ -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

<video controls autoplay loop style="display: block; margin: auto;">
<source src="../../../video/day07.mp4" type="video/mp4">
</video>
Binary file added docs/video/day07.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7c203be

Please sign in to comment.