Tuesday, May 12, 2015

The iHacklab Game of Logic

How to build and control a Guessing Game with LEDs on an Arduino:
by J.B. Wylzan


Project 9:  Thinking Lights

This project is a game about logic. Player/s will guess which Led will turn on next.  The  setup will also be used to test your motorshield and dc motors as we start to design our robots.





Hardware:
4 LEDs
4 resistors 
connecting wires
breadboard
Arduino R3 UNO board

Component Diagram:



Code # 9:
/*
   iHacklab The Game of Randomness
   powered by Arduino
   sketched by J.B. Wylzan
   modified by Lawsinium

  The Game of Logic: World of Guessing 
  This example code is public domain.
 */

long randNumber;
int y = 1000;

void setup(){
  Serial.begin(9600);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}

void loop() {
  randNumber = random(0, 5);      // print a random number from 0 to 4
  Serial.println(randNumber);
  delay(500);
  
   switch (randNumber) {
  case 1:    
    Serial.println("yellow led");
    digitalWrite(3, HIGH);   // turn the LED on
    delay(y); 
    digitalWrite(3, LOW);    // turn the LED off 
    break;
  case 2:    
    Serial.println("green led");
    digitalWrite(5, HIGH);   // turn the LED on
    delay(y); 
    digitalWrite(5, LOW);    // turn the LED off 
    break;
  case 3:    
    Serial.println("red led");
    digitalWrite(6, HIGH);   // turn the LED on
    delay(y); 
    digitalWrite(6, LOW);    // turn the LED off 
    break;
  case 4:    
    Serial.println("blue led");
    digitalWrite(9, HIGH);   // turn the LED on
    delay(y); 
    digitalWrite(9, LOW);    // turn the LED off 
    break;
  } 
  delay(1);      
  
}  // end of program


// Challenge: Write a sketch that will turn ON and OFF the Leds as shown in the table below:

L=Low ; H=High

Actual Layout:


Procedure:
1. Use the model as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #9 above
5. Paste Code #9
6. Click File > Save
7. Click Verify
8. Click Upload
9. Leds will turn On and Off randomly.


Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ================================================================== 


No comments:

Post a Comment