element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Partners
    Products & Partners
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum Arduino Programming_Vertical Menu_Mathematics
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 2 replies
  • Subscribers 338 subscribers
  • Views 546 views
  • Users 0 members are here
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

Arduino Programming_Vertical Menu_Mathematics

shoemakersp
shoemakersp over 13 years ago

Hello,

I have what is really a math question that is a bit over my head. I am looking for a way to display all of my choices in a vertical menu and use one chunk of code in a loop to display it. The math to show two is basic, but this has me lost. If it is possible, would anyone know what this is called or how to solve it?

 

Column represent the trips through the for loop:

 

A B C D E F | G

0 1 2 3 4 5 | 0

1 2 3 4 5 0 | 1

2 3 4 5 0 1 | 2

3 4 5 0 1 2 | 3

4 5 0 1 2 3 | 4

5 0 1 2 3 4 | 5

 

It just needs to shift everything up one each time and then loop back to zero.

TIA,

-Shoe

  • Sign in to reply
  • Cancel
  • shabaz
    0 shabaz over 13 years ago

    Hi Sean,

     

    I'm not sure I fully understand, but is this the type of thing you mean?

    I didn't really use any math for it, because the sequence you have shown takes up

    very little space in ROM, so I just add 1 per iteration.

    You could also use strncpy to tidy it, but maybe some microcontroller C libraries may

    not have a string implementation (I don't know).

     

    const char myline[]={'0', '1', '2', '3', '4', '5', '0',

                         '1', '2', '3', '4', '5' };


    int

    main(void)

    {

        int i;

        int forever=1;


        do

        {

            for (i=0; i<6; i++)

            {

                printf("%c%c%c%c%c%c%c\n", myline[i], myline[i+1], myline[i+2], myline[i+3],

                                           myline[i+4], myline[i+5], myline[i+6]);

            }


        } while(forever);


        // this line will generate a warning:

        return(0);

    }


    I just tried it, this is the output:

    0123450

    1234501

    2345012

    3450123

    4501234

    5012345

    0123450

    1234501

    2345012... etc

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • shoemakersp
    0 shoemakersp over 13 years ago in reply to shabaz

    Thank you so much Shabaz for the quick reply and correctly understanding my intent. I was having a hard time wrapping my head around it. I think I was actually headed in that direction, but couldn't see the loop. I was using this to display a menu on the Arduino. I have the following snipet outputing to the serial monitor.

     

    I started with the the example http://www.hw2sw.com/2011/09/22/circular-menu-in-arduino/2/, but I thought it would look cooler if all options were displayed at once.

     

    /* This is a section of code to display a menu. It is part

    of a larger sketch that selects a sensor for calibration.

    The sensor measures the differential pressure to determine

    the amount of liquid in a tank.

    */

    const int modeBtn = 4; //the MODE button

    int modeCounter = 0;

    int modeState = 0;

    int modeLastState = 0;

     

     

    const int testStart = 3; //the START button

    int testState = 0;

     

     

    // array of tank names

    char* tankSet[] = {"15W-40", "5W-30", "Waste", "W-Wash", "Coolant",

    "15W-40", "5W-30", "Waste", "W-Wash", "Coolant"};

     

     

    void setup()                    

    {

      Serial.begin(9600);

     

      pinMode(modeBtn, INPUT);

      pinMode(testStart, INPUT);

       

      ClearScreen();

            Serial.println("Tank To Calibrate?");

            Serial.println("MODE to scroll or");

            Serial.println("START to select");

    }

    void loop() 

    {

      

      modeState = digitalRead(modeBtn); //Determine state of MODE Button

      testState = digitalRead(testStart); //Determine state of MODE Button

      int modeCounter = 0;

     

      if (modeState != modeLastState) //Did it change?

        {

        if (modeState == LOW) //If the MODE button was pressed, start the Menu

          {

          if (modeCounter < 4)

          {

            modeCounter++;

          } else {

            modeCounter = 0;

          }

            ClearScreen(); 

            Serial.println("Tank To Calibrate?");

            Serial.println("MODE to scroll or");

            Serial.println("START to select");

            Serial.print("   >TANK: ");

            Serial.println(tankSet[modeCounter]);

            Serial.print("    tank: ");

            Serial.println(tankSet[modeCounter+1]);

            Serial.print("    tank: ");

            Serial.println(tankSet[modeCounter+2]);

            Serial.print("    tank: ");

            Serial.println(tankSet[modeCounter+3]);

            Serial.print("    tank: ");

            Serial.println(tankSet[modeCounter+4]);

        }

      }

      modeLastState = modeState;

     

      if (testState == LOW) //The START Button

      {

          Serial.print("Calibrating ");

          Serial.print(tankSet[modeCounter]);

          Serial.println(" Tank.");    

      }

    }

    void ClearScreen(){

      int i;

      for (i = 0; i < 15; i = i + 1) {

        Serial.println();

      }

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube