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 more Arduino silliness.
  • 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 23 replies
  • Subscribers 385 subscribers
  • Views 4195 views
  • Users 0 members are here
  • arduino IDE 2.0.3
Related

more Arduino silliness.

phoenixcomm
phoenixcomm over 2 years ago

As a C programmer and learning Java,  I like to keep things VERY SIMPLE!!!

so normally I would have my file pins.h which would include a bunch of #defines like RST_1 13, etc. This now keeps me sane when trying to use it and stops me from wondering if is it this pin or that pin. (for amplification please see it below.  

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

So in the same header file I also want my pinMode statements which now can use my mnemonics rather than the stupid pin number.  this now is hitting close to 20-30 lines. 

#define RST_1 13
#define RST_1 12
pinMode(RST_1, OUTPUT);
pinMode(RST_2, OUTPUT);
BUT THE IDE tosses errors like  error: expected constructor, destructor, or type conversion before '(' token pinMode (RST_1, OUTPUT);

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 2 years ago +4
    Hi Cris, It might be because the first line is defining RST_1, but the second line is defining it a second time, i.e. it states RST_1 on the second line too, where it should be RST_2 I guess. However…
  • baldengineer
    baldengineer over 2 years ago in reply to phoenixcomm +4
    phoenixcomm said: THEREFORE either the definition of pinMode(pin, mode); LIES where pin MUST be a value. which I don't believe THEN AND I DO BELEIVE the #define is not being substituted at compile time…
  • ntewinkel
    ntewinkel over 2 years ago in reply to shabaz +4
    shabaz , that looks great. I like your organized programming style. I totally agree on the readability of the code - it's not often we're stuck with the tiniest of chips anymore, so I too will choose…
Parents
  • Andrew J
    Andrew J over 2 years ago

    Ntewinkel is right.  Another way of looking at it, depending upon where in your C file you include that header, is you are trying to run code outside of a function, whether that is setup(), loop(), main(), anoFunction().  You can put code in an include file, along with the pin definitions as long as the include statement is placed inside a function.  HOWEVER, you must be aware of the ordering of code when the compiler processes all this: if it finds a reference to RST_1 before it has been included it will throw an error.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Andrew J
    Andrew J over 2 years ago

    Ntewinkel is right.  Another way of looking at it, depending upon where in your C file you include that header, is you are trying to run code outside of a function, whether that is setup(), loop(), main(), anoFunction().  You can put code in an include file, along with the pin definitions as long as the include statement is placed inside a function.  HOWEVER, you must be aware of the ordering of code when the compiler processes all this: if it finds a reference to RST_1 before it has been included it will throw an error.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
  • phoenixcomm
    phoenixcomm over 2 years ago in reply to Andrew J

    andrew j yes but the #define #typedef and the such are handled be the PRE-PROCESSOR which means If my defines are in global space EVERYBODY see them.  I understand compiles / interpreters very well as I have written a few in my time. pleas see my next comment you'll like it.

    • 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