BASIC: Blink LED w/ Push Button Using DO...WHILE Loop

  • MHB
  • Thread starter ineedhelpnow
  • Start date
  • Tags
    Loop
In summary, the conversation discusses using the DO...WHILE...LOOP statement to blink an LED at a rate of 2 times a second while a push button is pressed. It also mentions the need for a separate master DO...LOOP to continuously repeat the program while waiting for a button press. The circuit and the complexity of using APIs for tasks such as controlling circuits are also mentioned, with a comparison to the relative ease of writing programs for simple computations and output. The conversation concludes with uncertainty about which API should be used for working with circuits.
  • #1
ineedhelpnow
651
0
use the DO...WHILE...LOOP statement to blink an LED at a rate of 2 times a second as long as a push button is pressed. If the push button is not being pressed, the program should wait until the button is pressed and held before blinking the LED. To solve this problem, the DO...WHILE...LOOP will need to be inside of a separate master DO...LOOP that is used to allow our program to continuously repeat itself while waiting for a button press.

please help! i have no idea what to do.
the circuit looks something like this
View attachment 3412
 

Attachments

  • asdfdg.png
    asdfdg.png
    8.5 KB · Views: 79
Technology news on Phys.org
  • #2
Writing programs that do some computations with numbers or strings and output them to a console ([m]cout[/m] in C++) is the easiest. As soon as we involve APIs (application program interfaces, i.e., libraries that deal with a specific topic), such as those that are used to write graphical user interface or control circuits, things become significantly more complicated. Not only are there different APIs for the same task, but those APIs are often huge and require writing a lot of code even for simple tasks. For example, reading a name from a console and printing "Hello, <name>" can be done in a couple of lines. Writing a program that displays a window with a text box, a button and a label (output area) may take tens of lines.

So, I have no idea which API you are supposed to use to work with circuits.
 

FAQ: BASIC: Blink LED w/ Push Button Using DO...WHILE Loop

1. What is BASIC and what does it stand for?

BASIC stands for Beginner's All-purpose Symbolic Instruction Code. It is a high-level programming language that was created in the 1960s to make it easier for non-experts to learn and use computer programming.

2. How do you use a DO...WHILE loop in BASIC?

In BASIC, a DO...WHILE loop is used to repeatedly execute a set of instructions while a certain condition is true. The loop begins with the DO keyword, followed by the instructions to be executed. The loop will continue to run as long as the condition specified after the WHILE keyword is true. Once the condition becomes false, the loop will end and the program will move on to the next line of code.

3. What is the purpose of using a push button in a program?

A push button is a type of input device that can be used to trigger an action in a program. In the context of this BASIC program, the push button is used to control the blinking of an LED. When the button is pressed, the LED will turn on, and when it is released, the LED will turn off.

4. Can you explain how the "Blink LED w/ Push Button Using DO...WHILE Loop" program works?

Sure! The program first sets up the necessary variables and pins to control the LED and push button. Then, it enters a DO...WHILE loop that checks the state of the push button using the DIGITALIN command. If the button is pressed, the LED will turn on and the loop will continue to run. Once the button is released, the LED will turn off and the loop will end. This process will continue as long as the program is running.

5. Are there any potential issues to watch out for when using a DO...WHILE loop in a program?

Yes, there are a few things to keep in mind when using a DO...WHILE loop. It's important to make sure that the loop will eventually end by including a condition that will eventually become false. Otherwise, the program could get stuck in an infinite loop. It's also important to avoid any potential errors or mistakes in the instructions within the loop, as they will be repeated until the loop ends.

Back
Top