Saturday, September 29, 2007

Grandma and Grandson_The Third Version

I change my project a lot. (Hope you will like it...I will show it on Monday...)The following is my code.
I get the code work and I change a little bit. I use more than one LEDs so I set int num_pins=5.
If you olny have one LED, you can ignore: "int pins[] = {
2, 3, 4, 5, 6 };" and "int num_pins=5;" The code works but it may not the perfect one. Let's study together.
:)

int benCounter=0;
int justSwitched=0;
int highdelay=500;
int lowdelay=100;
int pins[] = {
2, 3, 4, 5, 6 };
int num_pins=5;

void setup() {

pinMode(7,INPUT);
int i;
for(i=0; i< num_pins; i++){
pinMode(pins[i],OUTPUT);
}

digitalWrite(6,LOW);
justSwitched==0;

}
void loop() {

if (digitalRead(7)==1 && justSwitched==0)
{
benCounter = benCounter + 1;
justSwitched = 1;
if (benCounter == 1)
{

digitalWrite(pins[0],HIGH);
delay(highdelay);
digitalWrite(pins[0],LOW);
delay(lowdelay);
}
else if (benCounter == 2)
{
int i;
for(i=0; i<2;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}

}
else if(benCounter == 3)
{
int i;
for(i=0; i<3;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}

}
else if(benCounter == 4)
{
int i;
for(i=0; i<4;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}
}
else if(benCounter == 5)
{
int i;
for(i=0; i<5;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}
}
else if(benCounter >= 6)
{
int i;
for(i=0; i digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
}
for(i=num_pins - 1; i>=0;i--){
digitalWrite(i,HIGH);
delay(highdelay);
digitalWrite(i,LOW);
}
}
}
else if (digitalRead(7)==1 && justSwitched==1){
benCounter = benCounter;
justSwitched =1;

if (benCounter == 1)
{
digitalWrite(pins[0],HIGH);
delay(highdelay);
digitalWrite(pins[0],LOW);
delay(lowdelay);
}
else if (benCounter == 2)
{
int i;
for(i=0; i<2;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}
}
else if(benCounter == 3)
{
int i;
for(i=0; i<3;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}
}
else if(benCounter == 4)
{
int i;
for(i=0; i<4;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}
}
else if(benCounter == 5)
{
int i;
for(i=0; i<5;i++){
digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
delay(lowdelay);
}
}
else if(benCounter >= 6)
{
int i;
for(i=0; i digitalWrite(pins[i],HIGH);
delay(highdelay);
digitalWrite(pins[i],LOW);
}
for(i=num_pins - 1; i>=0;i--){
digitalWrite(i,HIGH);
delay(highdelay);
digitalWrite(i,LOW);
}
}
}
else if (digitalRead(7)==0 && justSwitched==1) {
int i;
for(i=0;i<5;i++){
digitalWrite(pins[i],LOW);
}
justSwitched = 0;
}
else{
int i;
for(i=0;i<5;i++){
digitalWrite(pins[i],LOW);
}
justSwitched = 0;
}
}

Grandma and Grandson_The Second Version



I tried to refine my project, Grandma and Grandson. In the original work, there is only one LED. Before when the winner used metal to connect the circuit, the LED's light would be turned on. Now, when winners successfully connect the ciruit, they will turn on a heart shaped light. It blinks in a sequence. The light consists of ten LEDs. The following video shows the heart shaped light's flashy effect.

Tuesday, September 11, 2007

"Blinking"

Yesterday (Sep 10th), I saw many cool assignments. My classmates used various ways to present their games. Two of them used water in their games.

In class, I learned:

1) I can use water to make a circuit.

2) Arduino: INPUT/ OUTPUT/ HIGH/ LOW...

I could not wait to try, so I did my first try this morning. "Blinking" Fortunately, I did not burn anything.

Tuesday, September 4, 2007

A simple game_Gramdma and Grandson


This game is inspired by a true story. It happened after World War II. The main characters are a grandma and her grandson. After World War II, people were very poor. The grandson felt his grandma was so strange because she always tied a line to her leg with a magnet attach when she went out to work. Finally, he found out that his clever grandma used the magnet to collect metal on the street.

The game uses the same principle. Grandma and Grandson are two main characters in the game. The maximum number of the players is two. Players should pick up one doll in the beginning. After one of the player counts down from three then they can start the game. Players should hold the dolls and drag the magnets to get at least six pieces of metal from the road. The winner will be the one who successfully runs home and uses all of metal to connect the light! :)