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 Pressing a key
  • 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 8 replies
  • Subscribers 393 subscribers
  • Views 637 views
  • Users 0 members are here
Related

Pressing a key

joey1988
joey1988 over 10 years ago

Hello. I was wondering how I could make an LED blink and then stop it, when pressing a certain key on the keyboard. Similar to a power switch. Any ideas for a source code ? Thank you !

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 10 years ago in reply to joey1988 +4
    Hi George, While you won't find source code that does exactly what you want (it is like the Tower of Hanoi - as simple as the Arduino is, it could take longer than the life of the planet for people to…
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to shabaz +3
    Agree with Paul. Frankly I don't understand the sense of expecting to have a code as needed, already working. Why not sending a pre programmed Arduino? I don't want to offend anyone, but I think that it…
  • gadget.iom
    gadget.iom over 10 years ago in reply to shabaz +2
    Very nicely put shabaz . We are more than happy to assist any member on here, but we need a bit of a starting point. For example, you say "the keyboard", which means very little to us without knowing what…
  • gadget.iom
    gadget.iom over 10 years ago

    My initial thoughts are yes. Yes you can.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • joey1988
    joey1988 over 10 years ago

    Paul, do you have any ideas about the source code ? Do I need anything else besides the board, A-B connection, jumper wires and LED ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 10 years ago in reply to joey1988

    Hi George,

     

    While you won't find source code that does exactly what you want (it is like the Tower of Hanoi - as simple as the Arduino is, it could take longer than the life of the planet for people to write up all combinations of things people might want to do with the board!), so why not go through a tutorial concerned with controlling an LED, and a tutorial concerned with button presses, and perhaps an Arduino programming and C programming tutorial. These should provide sufficient information to get you started - there are no short-cuts to learning in this world : ( Give a man a fish and he eats for just one day..

     

    You'll learn more through going through the tutorials, and any issues, post them here, there are Arduino experts here who could help with an inspection if you can be specific about the issue you're seeing.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • gadget.iom
    gadget.iom over 10 years ago in reply to shabaz

    Very nicely put shabaz.

     

    We are more than happy to assist any member on here, but we need a bit of a starting point. For example, you say "the keyboard", which means very little to us without knowing what kind of keyboard you have in front of you.

    imageimage

     

     

    The best advice I can give you is to follow the advice given by shabaz, and follow some tutorials, then try to combine what you've learned. If you have come back to us at this point we will be in a much better possition to assist you. image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • onemikeoscar
    onemikeoscar over 10 years ago

    Yes you can but my advice it's the same from my other partners (paul and shabaz). I can put here a little piece of pseudo-code to guide you.

     

    bool last_state_on = false;
    void setup(){
         pinMode(pin_to_stop_blink, INPUT);
         pinMode(pin_led, OUTPUT);
    }
    
    void loop(){
         if(digitalRead(pin_to_stop_blink) == LOW) //ACTIVATE IN HIGH {
              if(last_state_on == false){
                   last_state_on = true;
                   digitalWrite(pin_led,HIGH);
              }else{
                   last_state_on = false;
                   digitalWrite(pin_led,LOW);
              }
         }else{
              digitalWrite(pin_led,LOW);
         }
    }

     

    The code is tooooooo simply but i think that for the first step is better go piecemeal. If you continue with Arduino you will discover a many things to improve in this code.

    Try by yourself image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • gadget.iom
    gadget.iom over 10 years ago in reply to onemikeoscar

    You might need to add a delay in the code as well, otherwise the blinking will occur too fast to be perceived by the human eye. image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago

    Hi!

    If it is a computer keyboard, you could detect the key press with Processing and by serial communication with the Arduino, control the LED image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to shabaz

    Agree with Paul. Frankly I don't understand the sense of expecting to have a code as needed, already working. Why not sending a pre programmed Arduino? I don't want to offend anyone, but I think that it is the worth that "making a project" is something implying a bit of independent thinking, not an exercise of copy and paste ... image

    • Cancel
    • Vote Up +3 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