DIY Gamer Conversion

Posted on
Page
of 2
Prev
/ 2
  • If fact you should really define your 'display' buffer as display=new Uint8Array(8) and then do display.set(graphics.buffer).

    Espruino shouldn't really let you access the bytes in the 'raw' ArrayBuffer

  • cheers @gordon, that works a treat.

    Just playing with some simple logic (capturing button presses) at the moment, and currently hitting what I feared, that the additional logic affects the display loop and so causes stuttering / flickering as it has stuff to compute.

    Not sure what can be done here though as ultimately I guess it's coming down to computations and without uber optimizing everything, the fact we have to refresh the screen the way we do means this is always going to be the case isn't it?

    Matt

  • I'd love to see your write up if you get that working.

    I tried it out and it's dead simple - Connect up LM339 to +3.3 and gnd, and pick one of the 4 comparators in it... Output goes to the pin you'll setWatch() on, one input goes to a reference voltage (you can make these with analogWrite() to the DAC pins), and the other input is the analog voltage you're reacting to. When the In+ is at a higher voltage than In-, the output goes high. For reasons not immediately clear to me, in my testing, I had to use the debounce option on setWatch(), otherwise the watch would be triggered repeatedly while the output was high. I'm sure there are improvements that can be made to this, but this should give you enough to get started with (since I'm not sure when I'll have a chance to write up the doc nicely - I'd like to include in the doc a "change detector" setup, for use with those 20 cent chinese vibration "sensors").

  • You can usually add 2 resistors to the LM339 (one between the DAC and it, and one from its output back to the pin the resistor from the DAC was connected to), and that'll give it some hysteresis and make it less likely to turn on and off.

    Hmm... if only there was a markdown for circuits :(

    @mattbrailsford If you do what I suggest with the fully unrolled loop (and call it maybe every 10ms) then it'll make the display a lot less glitchy (although a bit more dim).

  • @Gordon when you say unravel updateRow do you just mean call it 8 times all at once? Or is there a way to send a whole screen full of data? If so, do you have an example of how?

    @DrAzzy that sounds cool. Think I might have to give that a go :)

    Cheers

    Matt

  • Yes, just add a loop inside it that repeats 8 times. You might need something at the end to turn off the last row of leds though.

  • Hey @Gordon, I thought that's what you meant, unfortunately it still struggles a bit :( It keeps a constant steady colour, but they you just get the odd moment where it just struggles and you get flickering (like an old tv in and out of reception).

    I've got some other LED matrix screens on order so I'll see how they perform and maybe have a go at creating my own board. If you do have any other suggestions though, I'd be glad to hear them (you've been really helpful already).

    Matt

  • Are you aware that the LM339 is open colektor, so it needs a pullup resistor.

  • Hm, I wasn't, that's probably (part of) my problem. I'll try setting pinMode(pin,'input-pullup') and see if that improves things.

  • There's one more option, which is pretty hardcore:

    • Create some in-line assembler to bit-bash out the display output
    • Set up PWM on a pin with a frequency of 1kHz (to enable the timer)
    • Use poke32 to set the interrupt vector table to point to your inline assembler
    • Enable interrupts for that timer.

    As I say, pretty hardcore, and probably not recommended :)

  • Hey Guys, so if you've seen any of my other posts on the forums, you'll know that I've now switched out the display for an Adafruit 8x8 BiColor matrix. The benefits are two fold. 1) it has more colours and 2) it has an in-built oscillator so there is no need to keep updating it row by row, instead I can just send it a picture to draw, and it'll keep drawing it till you tell it otherwise. This should hopefully take a lot of pressure off the Espruino.

    So, I'm now playing with wiring up the buttons. I did some initial tests a while ago and could detect the buttons, however on playing with it today, there does seem to be some issues. Looking at the wiring, all the buttons are wired:

    3.3v ADC PIN > BTN > Grnd
    

    Now, when I setWatch on the buttons like so:

      setWatch(function(){ console.log("UP"); }, UP, { repeat:true, edge:'falling', debounce:10 });
      setWatch(function(){ console.log("LEFT"); }, LEFT, { repeat:true, edge:'falling', debounce:10 });
      setWatch(function(){ console.log("RIGHT"); }, RIGHT, { repeat:true, edge:'falling', debounce:10 });
      setWatch(function(){ console.log("DOWN"); }, DOWN, { repeat:true, edge:'falling', debounce:10 });
      setWatch(function(){ console.log("START"); }, START, { repeat:true, edge:'falling', debounce:10 });
    

    I do get the words printing to the terminal, but I also get them printed quite a few times after letting go of the buttons (my initial thoughts were just to do with debounce, but as you can see, that is set). And more weird, the start button (which is a differen type of button to the up/down/left/right ones) will trace just by touching the metal casing on the button.

    Would I be right in assuming then this sounds like a case of needing a pullup/pulldown resistor? if so, which kind would I need in this situation? and any suggestions on where best to wire them? (I wanna try and keep the gamer as stock looking as possible). If this isn't the issue, has anyone got any suggestions on what it might be?

    Many thanks

    Matt

  • Ok, figured it out :) So I just needed to pysically set the pin mode to input, and as the buttons are wired to ground, have the pin pull up by default, so adding the following, before registering the setWatches worked.

      pinMode(UP, 'input_pullup');
      pinMode(LEFT, 'input_pullup');
      pinMode(RIGHT, 'input_pullup');
      pinMode(DOWN, 'input_pullup');
      pinMode(START, 'input_pullup');
    

    I can now capture buttons :) whoop!

  • Check it out, first game done. Frogger :)

    http://youtu.be/ulyIF_csVTo

  • That looks fantastic - thanks :)

  • @Gordon the gamer board comes with a piezo buzzer on it. What would be the best tact on playing music whilst playing the game?

  • I'd suggest something like this: http://www.espruino.com/Making+Music as long as the buzzer is a speaker rather than a buzzer? It may be that all it does is beeps at one frequency?

    I think individual beeps for music are the best way forwards - you can use Waveform to play sounds when something happens, but trying to use it for Music alongside something else may cause pain :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

DIY Gamer Conversion

Posted by Avatar for mattbrailsford @mattbrailsford

Actions