Skip to content

Commit

Permalink
day 07
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepMartiElias committed Dec 6, 2024
1 parent 224ace0 commit a31a746
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
3 changes: 1 addition & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ hide:
1. Don't forget the stamp

!!! note annotate "7. Pianino (1)"
Day 07
[](solutions/07/07.md)
[Day 07](solutions/07/07.md)
1. Play me!

!!! tip annotate "8. Will you get the lowest temperature? (1)"
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 with 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>
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +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
- Day 7: solutions/07/07.md
#- Day 8: solutions/08/08.md
#- Day 9: solutions/09/09.md
#- Day 10: solutions/10/10.md
Expand Down

0 comments on commit a31a746

Please sign in to comment.