# vickingur

Member since May 2015 • Last active Jun 2015
• 1 conversations

• ### Espruino Star Wars (first steps)

started
• 4,670 views
• in Projects

Thanks for pointing to missing 'var' statements, I just overlooked that! I'm not using JavaScript often, so tend to forget simple things.

Yes, wave thing is for playing WaveForms. It's not used here as I didn't get it output something really interesting yet. I know it's somewhat confusing in this example, but I was planning to make a reusable module from Buzzer, which could play both WaveForm and simple pitches, so the code is mentioning waves.

As for the PITCHES - this is a copy-paste from espruino examples. And too me it's more clear to have quotes there. There is no need to dig into JavaScript magic in this case :)

Thanks for the feedback, it is really useful!

• in Projects

Thanks for suggesion regarding connecting both sides of seaker to PWM outputs!
It works nice. We tried to play with the same tunes for Star Wars. It sounds very different now, but still very special, so we decided to share it with you again:
https://vimeo.com/127748913

Not bad techno music for my taste :)

Also, this time I feel ready to share the code for this demo (still not perfect though), maybe it will help somebody.

``````BUZZER1 = B6;
BUZZER2 = B7;

BUZZER3 = B4;
BUZZER4 = B5;

function freq(buz, f) {
if (f===0) digitalWrite(buz,0);
else analogWrite(buz, 0.5, { freq: f } );
}

var pitches = {
'a':220.00,
'b':246.94,
'c':261.63,
'd':293.66,
'e':329.63,
'f':349.23,
'g':392.00,
'A':440.00,
'B':493.88,
'C':523.25,
'D':587.33,
'E':659.26,
'F':698.46,
'G':783.99,
'H':830.60
};

function Buzzer(pin, tune, led, wave) {
this.pin = pin;
this.tune = tune;
this.led = led;
this.pos = 0;
this.wave = wave;
}

Buzzer.prototype.reset = function() {
this.pos = 0;
};

Buzzer.prototype.step = function() {
var ch = this.tune[this.pos];
if (ch !== undefined) {
this.pos++;
print(this.pin+","+ch);
}
if (ch in pitches) {
if(this.wave!==undefined) {
wave(this.pin, this.wave, pitches[ch]);
} else {
freq(this.pin, pitches[ch]);
}
digitalWrite(this.led, 1);
}
else {
if(this.wave!==undefined) {
wave(this.pin, this.wave, 0); //off
} else {
freq(this.pin, 0); //off
}
digitalWrite(this.led, 0);
}
};

//           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   "
var tune1  = "AA  AA  AA  ff CAA  ff CAAAA    EE  EE  EE  HH ECC  ff CAAAA";
var tune2  = "a a a a a a a a a a a a f f g g a a a a f f g g a a a a a a a a e e e e e e e e e e e e g g f f c c c c f f g g a a a a aaaaaaaa";
var tempo = 150;
var tempo1 = 2*tempo;
var tempo2 = tempo;
var tempo3 = tempo;
var tempo4 = 2*tempo;

var buzzer1 = new Buzzer(BUZZER1, tune1, LED1, w1);
var buzzer2 = new Buzzer(BUZZER2, tune2, LED2, w2);

var buzzer3 = new Buzzer(BUZZER3, tune1, B15, w1);
var buzzer4 = new Buzzer(BUZZER4, tune2, B14, w2);

function resetTune() {
buzzer1.reset();
buzzer2.reset();
buzzer3.reset();
buzzer4.reset();
}

function initAudioAndLED() {
setInterval( function() { buzzer1.step();}, tempo1);
setInterval( function() { buzzer2.step();}, tempo2);
setInterval( function() { buzzer3.step();}, tempo3);
setInterval( function() { buzzer4.step();}, tempo4);
var resetInterval = Math.max(tune1.length*tempo1, tune2.length*tempo2);
setInterval(resetTune, resetInterval);
}

function onInit() {
initAudioAndLED();
}

onInit();
// save();

``````

The result was achieved pretty quickly, making me confident we can play even better tunes in future.

Thanks,
Victor

• in Projects

Hi All,

Thanks for positive feedback!

Gordon,

The first image was created just as bitmap buffer, then we found your ImageMagick tutorial and used it for creating other images. It worked very nice. The only thing is that we inverted colors in some images using '-negate' option.

Also, thanks for your suggestion about 2 pitches from 1 speaker - we're looking forward into investigating this, maybe it's possible to create a quartet from 2 speakers?)) We'll look into using waveforms as well, it seems promising.

It looks like our appetites are growing, so will keep you posted ;)

Thanks,
Victor

• in Projects

Hi guys!

Just started playing with my brand new Espruino Pico boards and can't stand sharing this.
I know it's very basic, but it's just.. so fun!!

So here are the results of me and my friend's 2 hours of life. We are just starting, so don't judge hard.
https://vimeo.com/127084624

Enjoy,
Victor

• in Interfacing

Yes, I tried that, but it didn't work, so I started to play in the left side.
Fortunately, the issue was just in IDE failing to download modules to default location.
Thanks!

• in Interfacing

Sorry, resolved the issue by specifying the path where to store downloaded modules in IDE

• in Interfacing

Hi Gordon,

I've got mine espruinos as well, thanks! Now I try to play with it and encountered similar issue - LCD examples do not work. Though, it looks like there is something with SW. It can't find PCD8544 module, which looks strange:

require("PCD8544")