Last active
January 28, 2018 22:18
-
-
Save bzamecnik/6fc8a306d41fecd81897edf345a1fc63 to your computer and use it in GitHub Desktop.
Arduino byte beats, https://youtu.be/gng2Gb0DHe4
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
/* | |
Byte beats. | |
More info: http://canonical.org/~kragen/bytebeat/ | |
Video: https://www.youtube.com/watch?v=gng2Gb0DHe4 | |
Circuit: | |
- 8 ohm speaker on digital pin 2 | |
- max 0.25 W, 250 ohm resistor to keep current low | |
My first meaningful Arduino project, beyond LED "hello world". | |
I tried to get the classic byte beats working, but unsuccessfully. | |
So I tried to make some my own formulas. | |
And they don't sound bad... :) | |
*/ | |
const int SPEAKER_PIN = 2; | |
//int t = 0; | |
void setup() { | |
for (int t = 0; t < 100000; t++) { | |
// 16-bit value | |
// int value = ((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7; | |
//good: | |
// int value = (t<<1) * 2 + (t>>2) | 21^t >> t | t>>3; | |
// value = (value << 3) % 256; | |
// int value = ((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7; | |
// ta, tada, ta | |
// int value = ((t << 4) ^ (t << 5) | (t << 6)) % 256; | |
// funny! | |
// int value = ((t << 1) ^ ((t << 5) | (t >> 2) | (t >> 3))) % 256; | |
// int value = (((t << 4) | (t << 3)) ^ ((t << 5) | (t >> 2) | (t >> 3))) % 256; | |
// int value = ((t << 1) + (t >> 1)) % 256; | |
// good rythm! | |
int value = (t << (t >> 4)) % 256; | |
// crystal block effect | |
// int value = (t << (t >> 8)) % 256; | |
// int value = ((t << (t >> 8)) | (t << 1)) % 256; | |
// int value = ((t << (t >> 8)) | (t << (t << 1))) % 256; | |
// fall | |
// int value = ((t << (t >> 8)) | (t << (t << 1))) % 256; | |
// int value = (t << (t*2 + t)) % 256; | |
// mole | |
// int value = (t << (t/3 + t)) % 256; | |
analogWrite(SPEAKER_PIN, value); | |
delayMicroseconds(125); | |
t += 1; | |
} | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment