Sunday, December 27, 2009

Project: Dice

I ran across this project for a single 6-sided die at the Electronics Club website and I was intrigued by their use of a grouped logic for presenting the results. I wanted to use my Duemilanova for both the randomizer and the LED driver though. Here are my results.

The first step was to set up the breadboard circuit. I'm using a solderless breadboard so I ended up with the seven pips on a diagonal.

7 pip die circuit

The logic of the circuit is this: every time an odd number is rolled on a die, the center pip is included. Every number other than one has pairs of pips showing, with or without the center.

So the center has a pin to itself (13), and the other pips are paired by the white jumpers. Each pair gets a pin, which allows me to represent 6 (actually 7) numbers using 4 pins -- and no decoder.

My first sketch computes a random number (using pin 0 as a seed as suggested in the randomize() documentation) from 1 to 6, turns on the appropriate pips, waits a second, then does it again.

Here's video:



And here's the sketch:

/*
Die

computes a random number from 1 to 6 and displays it using 7 LEDs as a die face

The circuit:
* LED connected from digital pin 13 to ground.
* 2 LEDs in serial connected from digital pin 12 to ground. (2s place)
* 2 LEDs in serial connected from digital pin 11 to ground. (4s place)
* 2 LEDs in serial connected from digital pin 10 to ground. (6s place)


Created 26 Dec 2009
By Anne Speck

*/

int die1; // container for current value of die1 (possible future expansion)
int basket; // variable for processing die values

int ledPin13 = 13; // LED connected to digital pin 13
int ledPin12 = 12; // 2 LEDs connected to digital pin 12
int ledPin11 = 11; // 2 LEDs connected to digital pin 11
int ledPin10 = 10; // 2 LEDs connected to digital pin 10

int one = LOW;
int two = LOW;
int four = LOW;
int six =LOW;

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin10, OUTPUT);

//use serial output for debugging
Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
// generate random number
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
die1 = random(1, 7);


// translate number into pins for display
basket = die1;
if (basket%2) {
//If there's a modulo, this is an odd number.
basket--;
one=HIGH;
}
if (basket == 6) {
//If six, turn on sixes place and subtract two
basket--;
basket--;
six=HIGH;
}
if (basket == 4) {
//If four, turn on fours place and subtract two
basket--;
basket--;
four=HIGH;
}
if (basket == 2) {
//If this has a value it's two.
basket=0;
two=HIGH;
}


digitalWrite(ledPin13, one); // set the LED on
digitalWrite(ledPin12, two); // set the LED on
digitalWrite(ledPin11, four); // set the LED on
digitalWrite(ledPin10, six); // set the LED on

//serial output for debugging
Serial.print("The number is: ");
Serial.println(die1);
Serial.print(one);
Serial.print(two);
Serial.print(four);
Serial.println(six);


delay(1000); // wait for a second

//Reset all pins
one = LOW;
two = LOW;
four = LOW;
six =LOW;

}

Labels: , , , , ,

Saturday, December 12, 2009

Aha!

I'm having aha moments left and right this weekend...

Thing I wish I'd been told in High School:
"Engineering is the useful application of science." (Will have to get the citation later. It's at the beginning of this lecture.)

Book I wish I'd read in college:
Mathematics for Liberal Arts by Morris Kline (Reprinted as Mathematics for the Nonmathematician)

Labels: ,

Tuesday, December 08, 2009

Science Education

On the 7th, NPR ran a story on TV shows that teach science. In that story they played clips from the President giving a speech (and welcoming Mythbusters to the White House) on the need for more science education in the United States. "More" is my word, and it's not quite right. He's trying to get Americans to care enough about scientific acheivements -- "meeting these challenges -- to improving our health and well-being, to harnessing clean energy, to protecting our security, and succeeding in the global economy" (from the linked speech) -- that we educate ourselves and our kids about science.

As Bill Nye says in the NPR article "Everybody loves science when he or she is young. You cannot find a kid that doesn't want to taste the kitchen floor, or that doesn't want to know how houseflies make a living."

The first question I had on hearing the quote from the president was, "But where are the jobs?" When I look at Craigslist, it isn't the science jobs section that is crammed full of good jobs. My sister, who majored in Biology, was qualified for a lab tech position on leaving school. It was her Master's degree in information systems that landed her a good job. I think enrollment in science is driven at least partly by the perception that there are an abundance of good jobs to go for at every level.

The second question I had was, "What do you mean by "science"?". We call psychology a science, but most people who major in it go into some form of counseling, not applying the scientific method in some form of research. The president welcomed the Mythbusters folks as examples of people who make science cool. But the Mythbusters lead-in calls Jamie and Adam special effects guys. They do apply the scientific method and use equations and record effects of their action. They propose and then prove or disprove hypotheses. So do you have to get a science degree to get their job?

The third question I had was, "You're talking about science education as a method, but innovation as the goal. Does innovation follow from education?" I think innovation happens when you have the skills to recognize and try a new idea and that may or may not come from education. The person I know who holds the most patents has something like a hundred thousand hours of hacking together electronics, reading spec sheets, trying code, talking to people, and running experiments under his belt. That's different from more classroom time.

The fourth question I had was, "but what if companies don't value science?" This is different from the jobs thing. Statistics and Calculus are the languages of the complex sciences, but at my company, managers weren't expected to be conversant in either. It wasn't a requirement to get promoted and it wasn't offered among the Seven Habits, creativity, work-life balance classes. Which is ironic, because the hit book in our industry at the time was about six-sigma investing.

Now, this is not to say I disagree with the president at all. And I don't think he'd disagree with me. There is a cultural inertia to overcome if we're really going to become conversant in science, and we each have to do our piece. His piece right now is to stem the tide of school districts deciding that science is optional. My piece is to get my but back to studying for my physics final.

Labels:

Tuesday, December 01, 2009

Hello World!

I picked up my Arduino Duemilanove board yesterday from Sparkfun and started working through Lady Ada's tutorial. This is from lesson 3. I wanted the lights to chase.

Labels: ,