-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16af4c9
commit 7c203be
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters