Nov. 20th, 2008

  • 1:00 AM
b/w
It's only up for a little while, but http://70.91.202.9/ is being served by this Arduino board:

Tags:

let's play whack-a-bug

  • Mar. 10th, 2007 at 7:43 PM
b/w
I've been working on a project for the entertainment system. I've cracked open my AV switch and I'm grafting in some extra smarts. Part of this requires me to decode a 2x4 button matrix that is being driven by another chip. Below is part of the code that is doing that decoding with notes in the comments. There's a fairly subtle bug in the code that had me scratching my head for a little while. It's not immediately obvious but it does make sense once you see it. The bug manifests itself as buttons 2, 3 and 4 not working when pressed.

Note:
The functions readButtons14() and readButtons58() are attached to interrupt lines and executed when RB2 and RB3 go high respectively.

#define debounce        500
int lastTime = 0;

/*
  The buttons on the system selector use a 2x4 matrix arrangement.
  RB2 and RB3 are the inputs to the matrix and RB4-7 are the outputs.
  
  RB2 pulses high for 50µs every 33ms (~30Hz)  RB3 then goes low for
  the remainder of the 33ms.
  
  We can check the states of RB4-7 during these times to see if a
  button has been pressed.  These are pulled low by 10k resistors tied
  to ground so a HIGH value means that a button has been pressed.
  
  RB2 --- 1 -- 2 -- 3 -- 4
          |    |    |    |
  RB3 --- 5 -- 6 -- 7 -- 8
          |    |    |    |
         RB4  RB5  RB6  RB7
*/

void readButtons14()  //RB2 has gone high
{
  int now = millis();
  if( lastTime + debounce < now )
  {
    lastTime = now;
    if( digitalRead(RB4) ) { doButton(1); }
    else if( digitalRead(RB5) ) { doButton(2); }
    else if( digitalRead(RB6) ) { doButton(3); }
    else if( digitalRead(RB7) ) { doButton(4); }
  }
}

void readButtons58()  //RB3 has gone high
{
  int now = millis();
  if( lastTime + debounce < now )
  {
    lastTime = now;
    if( digitalRead(RB4) ) { doButton(5); }
    else if( digitalRead(RB5) ) { doButton(6); }
    else if( digitalRead(RB6) ) { doButton(7); }
    else if( digitalRead(RB7) ) { doButton(8); }
  }
}


Can you figure it out?

Click to find the answer )

Nifty stuff

  • Dec. 4th, 2006 at 1:22 AM
geeky
If you've ever thought about playing with microcontrollers or wanted a way to build a simple interface to your computer then you should have a look at the oddly named Arduino board. The whole system is open source and includes the hardware and a clean and simple development environment for Mac, Linux and Windows. The language is like a stripped down C, with libraries that make accessing the hardware easy. I played around with it last night and got a temperature sensor working with a thermistor, and hooked up a tri-color LED and now have a rather ghetto ambient orb like device on my desk. So far my favorite feature is the usb-serial interface. In most microcontroller programming your output capabilities are generally limited to what you wire in yourself. With the Arduino you can very easily send some data down the serial line and watch it right in the IDE. In fact this feature helped me determine that the language reference is a little behind the times and that version 6 of Arduino includes bitwise operators (at least &, << and >>)

So how much does it all cost? About $35 for the basic board. I spent another $20 for a prototyping 'shield' board which has made tinkering much easier.

Tags: