Analyze an embedded C program
What does this part of the code mean in terms of the "if" and "while" statements
void blinkLed ( int blinkDelay, int ledPin )
{
static int blinkState = 0 ;
static int blinkTime = 0 ;
int currTime = millis ( ) ;
if ( ( currTime - blinkTime ) > blinkDelay )
{
blinkTime = currTime ;
if ( blinkState )
{
digitalWrite ( ledPin, HIGH ) ;
}
else
{
digitalWrite ( ledPin, LOW ) ;
}
blinkState = !blinkState ;
}
}
void beep ( int duration )
{
int startTime = millis ( ) ;
int currTime ;
while ( ( currTime - startTime ) < duration )
{
digitalWrite ( buzzerOutputPin, HIGH ) ;
delayMicroseconds ( 500 ) ;
digitalWrite ( buzzerOutputPin, LOW ) ;
delayMicroseconds ( 500 ) ;
currTime = millis ( ) ;
}
}
I'll explain what both functions beep() and blinkLed() do with pseudo code and sample dry run.
- blinkLed() will turn the LED on/off for the time period specified by blinkDelay i.e. change LED state once time blinkDelay has passed.
- beep() will toggle (turn on/off repeatedly) the LED state for the time duration. The toggle period will be 500 microseconds. After time duration, it will turn the LED to off state.
Explanation:
- Below is the pseudo code that tells what blinkLed() do.

- Below is the sample dry run for blinkLed() function.


- Below is the pseudo code that tells what beep() will do.

- Below is the sample dry run for beep() function.


Analyze an embedded C program What does this part of the code mean in terms of...
I'm trying to make a circuit from this code that I found for a personal project, but I'm having trouble figuring it out. Could someone make me a Circuit Diagram for this code with an LED, Servo, and Arduino Nano on BreadBoard. (No Battery, just use usb power from Nano) Thank You. Nano Code: const int servoPin = 5; const int buttonPin = 3; const int LEDPin = 4; #include <Servo.h> Servo visorServo; void setup() { visorServo.write(0); // Initial position...
Program is for an Arduino 1. Add the letters “A”, “b”, “c”, “d”, “E”, “F” to your homework program. Continually display “0123”, “4567”, “89Ab”, “cdEF” with a one second delay between each one. HINT: Expand pickNumber() to use numbers 10-15 (a-f in hex). Create new functions for a-f. (THIS IS THE CODE FROM THE HOMEWORK) /*************************************** name:Stopwatch function: you can see the number increases by one per second on the 4-digit 7-segment display. ***********************************/ //Email:support@sunfounder.com //Website:www.sunfounder.com /**************************************/ #include //the pins...
This question is about the Arduino code.
Please complete a 4-input circuit on your Arduino. Your circuit,
in addition to cycling through a binary representation of the
numbers 0-15 using LEDs, should use the Serial port to output the
decimal equivalent of each of the numbers in the format:
Output: 15
... if the value was 1111, and so forth.
You will be asked to upload your code as well as a photo of your
working breadboard circuit.
Add comments...
Design a circuit and Arduino program that accomplishes the following: An IR distance sensor will detect the presence (through waving of a hand) A H-Bridge circuit with 9V battery power will control the direction of the DC motor as described in Chapter 4 (pp. 70-79) of your textbook. When a hand is waved over the IR sensor, the motor moves in one direction (simulating opening a door). There is a 2 second pause, and then the motor moves in the...
ARM assembly using breadboard Ladder Game - This game involves a setup of LEDs in a row and a button. The goal is to get from the bottom led all the way to the top without them resetting. The LEDs will flash and you can only move up one led at a time, when the led is lit up, or else you get reset to the bottom. code in C please convert to ARM assembly #include <stdio.h> #include <stdlib.h> #include...
Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...
I have a program for Arduino written such that when I hold a
button down, it will turn an LED off. I want to be able to print to
the serial monitor how long the button was pressed for after I let
go of the button. Does anybody have any ideas? Below is the code I
have written thus far:
Text of Code:
#define LED RED_LED
#define buttonPIN PUSH2
const int buttonPin = PUSH2; // the number of the pushbutton...
Need help in filling the missing lines in the program template provided down below. (Arduino Uno). Using the program template provided, fill in the missing lines in the program which increments an unsigned integer variable when the “pin 2” button is pressed and decrements an unsigned integer variable when the “pin 3” button is pressed. Your program must display the integer variable (modulo 8) on the 7-segment LED display you designed in the previous lab. Once again you should be...
instructions These questions should test if you have understood the contents of Chapter 18 "Recursion". 1. What will this method return if you call it this: xMethod (4) static int xMethod (int n) { if (n == 1) return 1; else return n + xMethod (n - 1); } 1. 10 2. 11 3. 12 4. 9 2. Analyze the following code: public class Test { public static void main (String [] args) { int [] x = {1, 2,...
use the same code. but the code needs some modifications. so
use this same code and modify it and provide a output
Java Program to Implement Merge Sort import java.util.Scanner Class MergeSort public class MergeSort Merge Sort function / public static yoid sortfintfl a, int low, int high) int N-high-low; if (N1) return; int mid- low +N/2; Il recursively sort sort(a, low, mid); sort(a, mid, high); I/ merge two sorted subarrays int] temp new int[N]; int i- low, j-mid; for...