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
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
Arduino
  • Products
  • More
Arduino
Arduino Forum my second switch statement.
  • 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
  • Replies 4 replies
  • Subscribers 402 subscribers
  • Views 375 views
  • Users 0 members are here
Related

my second switch statement.

Former Member
Former Member over 13 years ago

I just wrote my first switch statemen and now Im working on the second but I cannot figure out why I get this error.  'states' was not declared in this case.  I am confused because it is just about the same as my first statement so why do I have this?

 

int state=8;

int mi=9;

int whichone;

int buttonst;

int buttonmi;

 

void setup()

{

Serial.begin(9600);

pinMode(state, INPUT);

pinMode(mi, INPUT);

buttonst=digitalRead(8);

buttonmi=digitalRead(9);

}

 

 

void loop()

{

switch(whichone)

  {

  case 0:

  buttonst=HIGH;

  buttonmi=LOW;

  states();

  break;

 

  case 1:

  buttonst=LOW&&buttonmi=HIGH;

  mis();

  break

 

  }

 

void states()

{

int states;

Serial.println("state");

delay (500);

 

}

 

 

void mis()

{

int mis;

Serial.println("mi");

delay (500);

 

}

 

}

  • Sign in to reply
  • Cancel

Top Replies

  • mconners
    mconners over 13 years ago +1
    It looks like you have the function states() defined inside the function loop(). That last curly brace needs to be moved up above where you defined void states() good luck. Mike
  • billabott
    billabott over 13 years ago

    Appears to be illegal overloading of name "states"

    I'll bet it was flagged in the bottom window of the 'Duino IDE.

     

    This is what I do when I get those hard to read error messages in the bottom window:

    1. Left click mouse to select message of interest.

    2. Right click mouse to 'copy' the highlighted text.

    3. Open Notepad or any other word processor.

    4. Paste the text into Notepad and make the font size large enough to easily see.

    5. Use my brain power to syntactically analyze the error message.   Informally this is called parsing.  image

    6. If there is some phrase I have no idea about; then it helps to look that part up on the WWW.

     

    -=SyntaxMatters=-

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mconners
    mconners over 13 years ago

    It looks like you have the function states() defined inside the function loop().

     

    That last curly brace needs to be moved up above where you defined void states()

     

    good luck.

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • mconners
    mconners over 13 years ago in reply to mconners

    BTW, this is an error as well, buttonst=LOW&&buttonmi=HIGH;

     

    Not sure what you are trying to do there

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mconners
    mconners over 13 years ago in reply to mconners

    The following will compile, not sure it does what you want though.

     

    int state=8;

    int mi=9;

    int whichone;

    int buttonst;

    int buttonmi;

     

     

    void setup()

    {

      Serial.begin(9600);

      pinMode(state, INPUT);

      pinMode(mi, INPUT);

      buttonst=digitalRead(8);

      buttonmi=digitalRead(9);

    }

     

     

    void loop()

    {

      switch(whichone)

      {

      case 0:

        buttonst=HIGH;

        buttonmi=LOW;

        states();

        break;

     

     

      case 1:

        buttonst=LOW;

        buttonmi=HIGH;

        mis();

        break;

      }

    }

     

     

    void states()

    {

      int states;

      Serial.println("state");

      delay (500);

    }

     

     

    void mis()

    {

      int mis;

      Serial.println("mi");

      delay (500);

    }

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