Archive for the ‘programming’ Category

The Tangible Countdown Timer

Wednesday, March 18th, 2009
An application I created to control a USB7 from a computer's serial port.

An application I created to control a USB7 from a computer's serial port.

The USB7

Quite a while ago, I discovered the USB7. It wasn’t until recently I actually thought I would have a use for it if I were to buy it. I was working on a website project due at midnight on a particular day. I was thinking how awesome it would be if I could have a bunch of LED 7-segment displays counting down the days, then hours, then minutes, then seconds, and finally hundredths of seconds. That was when I remembered it, the USB7. The USB7 is a relatively inexpensive, usb-controlled kit with six 7-segment displays. I haven’t seen many popular projects for it, though, so what does one do when there’s a need for something but it doesn’t exist? You make it! I bought a kit online, so it’ll arrive sometime later.

The Programming

Turning to Visual Studio Express 2008 and my brain’s Visual Basic abilities, I created this super-simple application that continually updates the display with the time remaining, fitting as much data as possible. For example, it can show up to 99 days, 24 hours, and 60 minutes when there’s more than 24 hours left. When there’s less than that, but still more than an hour, it’ll display a 2-digit hour code, a 2-digit minute number, and a 2-digit second number. Once you’re down to minutes, it shows minutes, seconds, and hundredths of seconds. Down to seconds, it’ll drop the minutes. Finally, once the timer’s up, it plays a crazy alarm sound and flashes constant zeroes all across the display. Now just to wait until it arrives!

Quick Comparison of (Programming) Languages

Monday, March 16th, 2009
Visual Studio is a non-free environment for the Visual language series.

Visual Studio is a non-free environment for the Visual language series.

It’s Good to Know

I had no idea about the differences between languages when I started to program. At first I learned HTML, then I went to Visual Basic. That was the mistake. Visual Basic is only available on Windows. After that, I seemed to want to continue to step down to lower and lower-level languages until I got to the base of it all. I’ve nearly succeeded, and went to C++, tried some Assembly, then turned to chip languages. I’m so far at Arduino/Wiring and some C. So, I want to give a ultra-quick comparison between common programming languages.

Visual Basic

Based off of original BASIC, Visual Basic is Microsoft’s .NET version. Compiled programs will only run on Windows or emulating environments, such as WINE. It’s a very simple yet powerful tool that can produce very nice GUIs.

Java

Cross-platform, Java is slightly slower, requires a JRE on target machines, is harder than most to learn, and requires skill to produce neat GUIs.

C++

Pure C++ has no built-in UI functions. Usually, OpenGL and other libraries are used. Very powerful, unmanaged code requires you clean up your memory mess or else the used RAM is not usable until reboot.

Python

Another powerful scripting language. Very popular, simple.

Lua

This is a very minimalistic language. I’ve only seen it used in odd little places like World of Warcraft addons and game scripting interfaces. In both cases, special functions are introduced to do other things in different languages. Lua interpreters can be integrated in many places where simple scripting is required.

Processing

Processing is very commonly used to create mathematical art, due to the easily accessible drawing functions. It is also used for interfacing to serial port devices and graphing or manipulating the data they send back.

Synopsis

From a job perspective, you should learn what the market seems to need at that particular time. For hobby things, use whatever you can do and think you’d like. You can almost always learn something different later!

Sudden Breakthrough!

Monday, February 16th, 2009

Not Exactly Pertinent...

Not Exactly Pertinent...

Image Copyright Protection!
I was thinking about this, and I don’t know why, but it struck me. It occurred to me what the best method of preserving an images quality while protecting against hotlinking and copyright abuse with minimal effort. So, the next morning, I wrote up all the code necessary to make it work. Now, I’m not actually going to describe the entire process, but instead leave it up to everyone to reverse engineer and figure it out! There should be enough there for anyone with basic HTML and CSS knowledge. The example is available here. Enjoy!

The Response Timer (Beta)

Saturday, February 14th, 2009
The basic breadboard wiring, as seen here, is simple. It's the code that's complex.

The basic breadboard wiring, as seen here, is simple. It's the code that's complex.

It Works!

It took way too long for such a simple thing. But, it works. I have, um, semi-successfully created a device that measures the precise time in milliseconds between an LED lighting and a user hitting the button. The button is, of course, made of an old floppy ripped to shreds and taped onto a micro-switch from some old appliance. The wiring is too simple, and would work with the configuration described under “Button” at arduino.cc. It spits numbers out to serial which can be viewed with HyperTerminal, and, in the future, Processing. At this moment, I keep pressing the button with my wrist as it’s so close to my keyboard.

I Can Has Code??

You certainly can has code. It’s based off of what I wrote about earlier, and has one minor major bug. Here goes:

int lightPin = 13;
int buttonPin = 2;
int resetPin = 4;
static int cyclesGlobal = 0;
boolean isTesting = false;
boolean killLoop = false;
void setup()
{
pinMode(lightPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(resetPin, OUTPUT);
digitalWrite(resetPin, HIGH);
Serial.begin(9600);
Serial.println(124, DEC);
}
void reset()
{
digitalWrite(resetPin, LOW);
digitalWrite(resetPin, HIGH);
}
void erraticSignal()
{
digitalWrite(lightPin, HIGH);
delay(200);
digitalWrite(lightPin, LOW);
delay(100);
digitalWrite(lightPin, HIGH);
delay(200);
digitalWrite(lightPin, LOW);
delay(100);
digitalWrite(lightPin, HIGH);
delay(200);
digitalWrite(lightPin, LOW);
delay(1000);
}
void alertStart()
{
Serial.println(246, DEC);
}
void lightOn()
{
digitalWrite(lightPin, HIGH);
}
void lightOff()
{
digitalWrite(lightPin, LOW);
}
void startTiming()
{
delay(200);
while(cyclesGlobal < 10000 && killLoop != true)
{
delay(1);
cyclesGlobal++;
}
phoneHome();
lightOff();
cleanup();
}

void phoneHome()
{

Serial.print(135, DEC);
Serial.println();
delay(100);
Serial.println(cyclesGlobal);
delay(1000);
}
void stopTimer()
{
killLoop = true;
}
void cleanup()
{
lightOff();
detachInterrupt(0);
cyclesGlobal = 0;
isTesting = false;
killLoop = false;
reset();
}
void spill()
{
//debug
/* Serial.println("Now spilling the beans...");
delay(200);
Serial.print("lightPin: ");
delay(200);
Serial.println(lightPin);
delay(200);
Serial.print("buttonPin: ");
delay(200);
Serial.println(buttonPin);
delay(200);
Serial.print("cyclesGlobal: ");
delay(200);
Serial.println(cyclesGlobal);
delay(200);
Serial.print("isTesting: ");
delay(200);
Serial.println(int(isTesting));
delay(200); */
Serial.print("killLoop: ");
delay(200);
Serial.println(long(killLoop));
delay(200);
}
void startTesting()
{

isTesting = true;

startWaiting();

attachInterrupt(0, stopTimer, RISING);
lightOn();
startTiming();
}
void startWaiting()
{
delay(random(2000, 10000));
}
void loop()
{
if (digitalRead(buttonPin) == HIGH)
{
if (isTesting != true)
{
erraticSignal();
alertStart();
startTesting();
}
}
}

Insecticide Please?

I swear, I worked many hours pinpointing the bug. I haven’t found a solution for it. I was able to theorize and implement a solution, but did it work? No. Anyways, after the first test, it starts freaking out and will only say your reaction time is 0. It ends up completely skipping the timing loop, and it even thinks that “0 < 10000″ is false. Right. My solution was to send a pulse to pin 4, which would have a jumper to RESET, in hopes of a self-reset within the program. No avail, but it’s still in the code in case it works for anyone else or something.

Arduino Reflex Tester! (Concept)

Thursday, February 12th, 2009
No reason. No reason at all.

No reason. No reason at all.

Why?

 

So many people ask the same question to so many ideas: why? And I answer so many of those questions with the same two words: why not?

What’s an Arduino?

If you don’t already know, an Arduino is an open-source hardware and software physical computing platform. So what’s that mean? Basically, you are given a very elegant language to program the Arduino circuit board with, and a very easy to use board to connect many kinds of sensors and output devices. It enables you to make things physically happen rather than just show up on a monitor!

Why Go To So Much Trouble?

The problem I’ve always seemed to run into is that, with Windows’ clunkiness and the fact there are many other applications running at the same time, it doesn’t go fast enough. Since it doesn’t go fast enough, you can’t accurately time a human reflex. While an Arduino runs at 16 MHz, and that’s not technically faster than an average computer, the Arduino runs a much lighter  ”operating system,” enabling it to run faster.

So… How?

This configuration depends on there being a jumbo LED on pin 13 of the Arduino and a switch with a 10k pull-down resistor configuration on pin 2. It will spit out some data to serial, which does need a program or your brain to comprehend. That said, here’s my hypothetical and untested code:

 

 

 

 

 

int lightPin = 13;
int buttonPin = 2;
int cyclesGlobal = 0;
boolean isTesting = false;
boolean killLoop = false;
void setup()
{
  pinMode(lightPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  serial.begin(9600);
}
void erraticSignal()
{
  digitalWrite(lightPin, HIGH);
  delay(200);
  digitalWrite(lightPin, LOW);
  delay(100);
  digitalWrite(lightPin, HIGH);
  delay(200);
  digitalWrite(lightPin, LOW);
  delay(100);
  digitalWrite(lightPin, HIGH);
  delay(200);
  digitalWrite(lightPin, LOW);
  delay(1000);
}
void alertStart()
{
  serial.println(246, DEC);
}
void lightOn()
{
  digitalWrite(lightPin, HIGH);
}
void lightOff()
{
  digitalWrite(lightPin, LOW);
}
void startTiming()
{
  for(long i=0; i <= 10000; i++)
  {
    if (killLoop == true)
    {
      break;
    }
    delay(1);
    cyclesGlobal = l;
  }
  lightOff();
  cleanup();
}
void phoneHome()
{
  serial.print(135, DEC);
  serial.println();
  serial.println(cyclesGlobal);
}
void stopTimer()
{
  detachInterrupt(0);
  phoneHome();
  killLoop = true;
  cleanup();
}
void cleanup()
{
  lightOff();
  cyclesGlobal = 0;
  isTesting = false;
  killLoop = false;
}
void startTesting()
{
  isTesting = true;
  startWaiting()

  attachInterrupt(0, stopTimer(), RISING)

  lightOn()
  startTiming()
}
void startWaiting()
{
  delay(random(2000, 10000));
}
void loop()
{
  if (digitalRead(buttonPin) == HIGH)
  {
    if (isTesting != true)
    {
      erraticSignal()
      alertStart()
      startTesting()
    }
  }
}

SmartTalk - Analyzing Your Chats (Concept)

Wednesday, February 4th, 2009
Google's chats are stored within the user's Gmail account.

Google's chats are stored within the user's Gmail account.

Concept

One day, it was like any other day. Gmail chatting with a friend. Not doing much. Then I started to think, what if I could see a ratio of how much I talk versus the person on the other end? Then I wondered what it would take to script something up to do precisely that. I was planning to use Visual Basic, but that would be Windows bound. Then I wanted to use Java. But then it wouldn’t work because I learn Java, forget it, learn it, forget it. I’m in my forgotten phase. I even considered Lua, the uber language. Then it struck me. PHP! The best hypertext preprocessor! Then the whole web-ter-net could enjoy it! I messed with PHP for a bit before realizing that Wordpress doesn’t like to play well with it. I guess it’s good for security.

Try It!

I really wish I could tell you to start using it today but I haven’t actually wrote it yet. I’m horrible at my Javascript, so it might take longer than one would expect. But, I promise, something will come of this.

Interpreting the Facts

Although not nearly as good as a psychiatrist or anything professional, you probably could see quite a bit into people’s personalities. If, for every word you say, your friend says five, you could tell they likely talk a lot. Or vise-versa. A small tool. Multiple possibilites. Coming soon to theajblog.