Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Noteblock
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fxk8y
Noteblock
Commits
5bb56da7
Commit
5bb56da7
authored
5 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parents
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+7
-0
7 additions, 0 deletions
README.md
noteblock.ino
+69
-0
69 additions, 0 deletions
noteblock.ino
with
76 additions
and
0 deletions
README.md
0 → 100644
+
7
−
0
View file @
5bb56da7
Noteblock
=========
Musik mit Druck!
[TODO]
This diff is collapsed.
Click to expand it.
noteblock.ino
0 → 100644
+
69
−
0
View file @
5bb56da7
#include
"MIDIUSB.h"
#include
<math.h>
// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).
uint16_t
period
=
0
;
uint64_t
cycle
=
0
;
uint8_t
state
=
0
;
void
note
(
uint16_t
frq
);
void
setup
()
{
Serial
.
begin
(
115200
);
pinMode
(
10
,
OUTPUT
);
}
uint16_t
midi2frq
(
uint8_t
number
)
{
// Serial.print(number);
// Serial.print(" | ");
double
_n
=
(
double
)((
double
)
number
-
(
double
)
69
);
// Serial.print(_n);
// Serial.print(" | ");
double
d
=
pow
((
double
)
2
,
_n
/
(
double
)
12
)
*
(
double
)
440
;
// Serial.println(d);
return
(
uint16_t
)
d
;
}
uint8_t
lastNote
=
0
;
void
loop
()
{
midiEventPacket_t
rx
;
rx
=
MidiUSB
.
read
();
if
(
rx
.
header
!=
0
)
{
char
buffer
[
256
];
sprintf
(
buffer
,
"header: 0x%X b1: %d b2: %d b3: %d"
,
rx
.
header
,
rx
.
byte1
,
rx
.
byte2
,
rx
.
byte3
);
Serial
.
println
(
buffer
);
if
((
rx
.
header
&
0x09
)
==
0x09
)
{
lastNote
=
rx
.
byte2
;
note
(
midi2frq
(
rx
.
byte2
));
Serial
.
println
(
"ONNNNNNN"
);
}
else
if
((
rx
.
header
&
0x08
)
==
0x08
&&
lastNote
==
rx
.
byte2
)
{
period
=
0
;
Serial
.
println
(
"OFFFFFFFF"
);
}
/* else {
char buffer[256];
sprintf(buffer, "header: 0x%X b1: %d b2: %d b3: %d", rx.byte1, rx.byte2, rx.byte3);
Serial.println(buffer);
} */
}
if
(
period
)
{
state
^=
1
;
digitalWrite
(
10
,
state
);
}
else
{
digitalWrite
(
10
,
LOW
);
}
cycle
+=
1
;
delayMicroseconds
(
period
);
}
void
note
(
uint16_t
frq
)
{
period
=
1000000
/
frq
/
2
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment