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
Dev Tools
  • Products
  • More
Dev Tools
Forum Raspberry Pi, combining commands
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Dev Tools to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 79 subscribers
  • Views 492 views
  • Users 0 members are here
  • raspberry
  • command
  • pi
  • combined
  • led
  • grouped
  • code
  • leds
  • group
Related

Raspberry Pi, combining commands

Former Member
Former Member over 12 years ago

Hi, so I am new to programming on the Pi, but am able to find most of the answers I want on how either I am having trouble finding an answer for the problem I am having.

 

At the moment I am playing around with LED's and buttons and am currently trying to combine and groups commands, what I mean by this is for example I have multiple LED's and am creating a sequence of turning them on and off but to save time instead of having to write the whole line of code to turn each LED on and off I would like to be able to write the command once and then rename it to fir example LED1on or LED3off.

 

I hope I have explained my self and if not just let me know and I will try and reword it.

 

Thanks

  • Sign in to reply
  • Cancel

Top Replies

  • johnbeetem
    johnbeetem over 12 years ago +1
    If I understand you correctly, I think what you want is to define a function with arguments for the LED number and whether you want to turn the LED on or off. Then you can just call the function for each…
Parents
  • johnbeetem
    johnbeetem over 12 years ago

    If I understand you correctly, I think what you want is to define a function with arguments for the LED number and whether you want to turn the LED on or off.  Then you can just call the function for each desired transition.

     

    There are examples of GPIO software for various languages at the RasPi Hardware Wiki.

     

    You also might re-post your question at the element14 Raspberry Pi group.  More Razzers may see it there.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • johnbeetem
    johnbeetem over 12 years ago

    If I understand you correctly, I think what you want is to define a function with arguments for the LED number and whether you want to turn the LED on or off.  Then you can just call the function for each desired transition.

     

    There are examples of GPIO software for various languages at the RasPi Hardware Wiki.

     

    You also might re-post your question at the element14 Raspberry Pi group.  More Razzers may see it there.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
  • Former Member
    Former Member over 12 years ago in reply to johnbeetem

    Henry,

       John gave a very good reference for examples.

     

    To explain a little bit more, there are commands that you type interactively

    at the "shell" prompt, such as 'ls' and 'pwd'.  You can use a text editor to create

    a file and put any of those shell commands into the file, then close the file,

    and then make the file executable, by typing

             chmod  +x  somefilename

    Then you can run the commands in the file from the command line by typing

    the name of the file.  To avoid any possible confusion with other files with the

    same name in other directories, it is safest to use './" in front of the file name, such as

          ./somefilename

     

    The './" means to use the file in the current directory (because '.' means current directory

    and '/' is the separator between directory names and file names).

     

    Alternatively, you could run the file by typing

        bash ./somefilename

    which is maybe less convenient, but doesn't require the 'chmod' step.

     

    bash is a shell command interpreter.  You can see an example from John's link.

    Besides putting simple commands in a bash script, you can add parameters to the

    script, just like the 'cat' command takes a parameter of which file to display.

    Typing 'man bash' will give you the manual for bash.

     

    Besides shell scripts, you can also put your commands in an interpreted programming

    language script, such as python, which also has an example in John's link.  That allows

    you do do more complex things in your script than you can do using bash.

    • 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