-
​Nyan Board by Radomir Dopieralski
10/31/2015 at 11:11 • 13 comments#Nyan Board by @Radomir Dopieralski
[UPDATE] Video and code added
So this should be an easy one, right? Oh how I failed. I'm still not getting sounds out of it, after I played around with libraries and different Versions of arduino. It's always tones and timers that get me.
I first thought the pads next to the attiny45/85 where a pullup resistor - d'oh. Of course it didn't do anything. Now it at least blinks.
To fit on an attiny45 I had to change the code a bit.
this code works, see the comments:
const int LENGTH = 27; const int NOTES[] PROGMEM = { 65, 67, 70, 67, 74, 74, 72, 65, 67, 70, 67, 72, 72, 70, 69, 67, 65, 67, 70, 67, 70, 72, 69, 65, 65, 72, 70 }; const int DURATIONS[] PROGMEM = { 25, 25, 25, 25, 75, 75, 15, 25, 25, 25, 25, 75, 75, 75, 25, 5, 25, 25, 25, 25, 100, 5, 75, 25, 100, 5, 100, 200 }; void play() { float bps = (60.0 / 120) * 1000.0; for (int i = 0; i < LENGTH; ++i) { int note = pgm_read_word_near(NOTES + i); int duration = pgm_read_word_near(DURATIONS + i); int hertz = (int) (pow(2.0, ((note - 69.0) / 12.0)) * 440); tone(4, hertz, (long) (duration * bps / 100) - 10); delay((long) (duration * bps / 100)); toggle_eyes(); } } void toggle_eyes() { PORTB ^= ( 1 << PB3 ); } void setup() { DDRB = ( 1 << PB3 ); DDRB = ( 1 << PB4 ); } void loop() { play(); }
#include "pitches.h" #include <avr/pgmspace.h> const int FREQ[] = { REST, NOTE_AS4, NOTE_AS5, NOTE_B4, NOTE_B5, NOTE_CS5, NOTE_CS6, NOTE_D5, NOTE_DS4, NOTE_DS5, NOTE_DS6, NOTE_E4, NOTE_E5, NOTE_E6, NOTE_FS4, NOTE_FS5, NOTE_GS4, NOTE_GS5, }; const signed char INTRO_NOTES[] PROGMEM = { 9, 12, -15, -4, 9, 12, 15, 4, 6, 10, 6, 2, -4, -15, 9, 12, -15, -4, 6, 2, 4, 6, 13, 10, 13, 4, 0 }; const signed char MELODY_NOTES[] PROGMEM = { -15, -17, 9, 9, 0, 3, 7, 5, 3, 0, -3, -5, -7, 7, 5, 3, 5, 9, 15, 17, 9, 15, 5, 9, 3, 5, 3, -9, -15, 17, 9, 15, 5, 9, 3, 7, 9, 7, 5, 3, 5, -7, 3, 5, 9, 15, 5, 9, 5, 3, -5, -3, -5, -15, -17, 9, 9, 0, 3, 7, 5, 3, 0, -3, -5, -7, 7, 5, 3, 5, 9, 15, 17, 9, 15, 5, 9, 3, 5, 3, -9, -15, 17, 9, 15, 5, 9, 3, 7, 9, 7, 5, 3, 5, -7, 3, 5, 9, 15, 5, 9, 5, 3, -5, -3, -5, -3, 14, 16, -3, 14, 16, 3, 5, 9, 3, 12, 9, 12, 15, -3, -3, 14, 16, 3, 14, 12, 9, 5, 3, 14, 8, 11, 14, -3, 14, 16, -3, 14, 16, 3, 3, 5, 9, 3, 14, 16, 14, -3, 3, 1, 3, 14, 16, 11, 12, 9, 12, 15, -3, -1, -3, 14, 16, -3, 14, 16, 3, 5, 9, 3, 12, 9, 12, 15, -3, -3, 14, 16, 3, 14, 12, 9, 5, 3, 14, 8, 11, 14, -3, 14, 16, -3, 14, 16, 3, 3, 5, 9, 3, 14, 16, 14, -3, 3, 1, 3, 14, 16, 3, 12, 9, 12, 15, -3, -5 }; #define BEEP_PIN 4 #define LED_PIN 3 #define SPEED 1500 void toggle_eyes() { static bool blink = false; digitalWrite(LED_PIN, blink); blink = !blink; } void play(const signed char *notes, const unsigned int length) { for (unsigned int n = 0; n < length; n++) { signed char f = pgm_read_word_near(notes+n); int d; if (f < 0) { d = SPEED / 8; f = -f; } else { d = SPEED / 16; } tone(BEEP_PIN, FREQ[f], d); delay(1.3 * d); noTone(BEEP_PIN); toggle_eyes(); } } void setup() { play(INTRO_NOTES, 26); } void loop() { play(MELODY_NOTES, 216); }
-
Pro Trinket USB Keyboard by Stefan Lochbrunner
10/28/2015 at 18:32 • 6 comments#Pro Trinket USB Keyboard by @Stefan Lochbrunner
[2015-10-31] started building
[2015-11-07] encoders are in, finally got it working (video proof)
When [Stefan] asked for one of my #Ignore this ESP8266 board 's, he send me one of his #Breadboard Widgets and I also asked for one of his Pro Trinket boards, since I had one or two trinkets in my drawer.
I ordered the parts needed, which was in fact everything except the trinket pro. Looking through eBay I found 12x12 mm tact switches with optional caps on them. Because I like purple, shapeways is able to print purple now and I found this file: http://www.thingiverse.com/thing:493729 that I changed a bit to make the caps bigger (12x12 instead 10x10) I am now in possession of this beauty. It is not soldered yet, but I love the look so far!
Build log
The LEDs came yesterday, so I could finally start building this beauty. I managed to solder the yellow and orange LEDs upside down - so my fix was to solder more LEDs on top of them :D I didn't get the keyboard functions to work though :( Gotta fiddle around with arduino libs and versions again.
Here are the button cap files:
http://www.thingiverse.com/thing:1097850
UPDATE
Thanks to Stefan who send me this link http://www.freebsddiary.org/APC/usb_hid_usages.php I found out that if you use 0xB3 and 0xB4 instead of the 0xB5 and 0xB6 for next and previous song commands, that you don't have to have the window active to switch tracks. At least in my microcosmos, where we also found out that TrinketHidCombo.isConnected() doesn't work.