Archive for the ‘arduino’ Category

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()
    }
  }
}