element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Help regarding code for 'Logic Tree' project using Arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 1 reply
  • Subscribers 390 subscribers
  • Views 190 views
  • Users 0 members are here
Related

Help regarding code for 'Logic Tree' project using Arduino

horizonb
horizonb over 8 years ago

The purpose of the project is to demonstrate Probability & Logic Tree to school students. The design consists of 3 buttons (START, YES, NO) & LEDs.

When START is pressed LED in front of the 1st question will glow. Answer of the question is YES or NO. So based on the button pressed next LED will glow in front of the next question which is again YES/NO type.

 

For example (see the attached image)

 

Let this be a number guessing game. Students are asked to guess a number between 1 & 10. So when START is pressed the LED1 will glow & besides the LED1 question is asked 'Is your number less than 5?' If answer is yes then YES button is pressed & then LED2 will glow (else LED3 will glow). So next question in front of LED2 is 'Is your number less than 3?'. If YES then LED4 will glow, if NO is pressed then LED5 will glow.

This will continue until the final answer is obtained. Note that as we proceed further the previous LEDs which were ON will still remain ON until the final step & will OFF only when START is pressed again (so that the entire branch is lit which reaches the answer).

 

 

I am having difficulties developing code(in ADE, using C)  for this project. I don't have any clue what should be my approach to this problem. Any help/suggestions/advice will be helpful.

Thanks.image

  • Sign in to reply
  • Cancel
Parents
  • beacon_dave
    0 beacon_dave over 8 years ago

    One simple way to do this might be to set a variable to hold the current location in the tree. When a switch is pressed then use that variable to determine what the next position in the tree is. Then turn on the LED and update the variable with the new current position.

     

    When the yes switch is pressed you could call a function something like:

     

    yes_pressed(current_position)

    {

      switch(current_position)

      {

          case 1:

          // next LED to light is 2 so turn on LED 2

          // set current position to 2

          break;

     

          case 2:

          // next LED to light is 4 so turn on LED 4

          // set current position to 4

          break;

     

          case 4:

          // next LED to light is 8 so turn on LED 8

          // set current position to 8

          break;

     

          case 8:

          // reached end of tree stop until reset is pressed

          break;

     

          ...

     

          default:

          // something went wrong - flash some lights as a warning

          break;

      }

    }

     

    Create another function for the no's which is called when the no switch is pressed.

     

    Reset turns off all the LEDs and sets the current position back to 0 or 1.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • beacon_dave
    0 beacon_dave over 8 years ago

    One simple way to do this might be to set a variable to hold the current location in the tree. When a switch is pressed then use that variable to determine what the next position in the tree is. Then turn on the LED and update the variable with the new current position.

     

    When the yes switch is pressed you could call a function something like:

     

    yes_pressed(current_position)

    {

      switch(current_position)

      {

          case 1:

          // next LED to light is 2 so turn on LED 2

          // set current position to 2

          break;

     

          case 2:

          // next LED to light is 4 so turn on LED 4

          // set current position to 4

          break;

     

          case 4:

          // next LED to light is 8 so turn on LED 8

          // set current position to 8

          break;

     

          case 8:

          // reached end of tree stop until reset is pressed

          break;

     

          ...

     

          default:

          // something went wrong - flash some lights as a warning

          break;

      }

    }

     

    Create another function for the no's which is called when the no switch is pressed.

     

    Reset turns off all the LEDs and sets the current position back to 0 or 1.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube