Question

Write a program that creates a square wave output. There are two possible frequencies, 100 Hz...

Write a program that creates a square wave output. There are two possible frequencies, 100 Hz and 200 Hz, depending on an input switch position. i.e. if input is = 0, the frequency is 100 Hz, otherwise, frequency is 200 Hz.

Homework Answers

Answer #1

//Arduino IDE code
int push_button = 2;
int square_wave_output = 5;

void setup()
{
pinMode(push_button, INPUT);  
pinMode(square_wave_output, OUTPUT);
}

void loop(){
  if (digitalRead(push_button)==LOW){ // If switch position is in zero
    digitalWrite(square_wave_output, HIGH);
    delay(5); //100Hz squae wave form ON period
    digitalWrite(square_wave_output, LOW);
    delay(5);} //100Hz squae wave form OFF period
   else{ // If switch position is in one
    digitalWrite(square_wave_output, HIGH); 
    delay(2.5); 200Hz squae wave form ON period
    digitalWrite(square_wave_output, LOW);
    delay(2.5);} //200Hz squae wave form OFF period   
  }
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1.Write pseudocode for a program that allows the user to input two numbers (X and Y)...
1.Write pseudocode for a program that allows the user to input two numbers (X and Y) and a code C. If the code has value 1, the program should output the larger of X and Y and otherwise output the smaller. Now convert your pseudocode to an assembly language program. Enter the program into the lab software assembler. Assemble the program and execute it with different input data. 2. Write pseudocode for a program that allows the user to input...
(C++) Write a program whose input is two characters and a string, and whose output indicates...
(C++) Write a program whose input is two characters and a string, and whose output indicates the number of times each character appears in the string. Ex: If the input is: n M Monday the output is: 1 1 Ex: If the input is: z y Today is Monday the output is: 0 2 Ex: If the input is: n y It's a sunny day the output is: 2 2 Case matters. Ex: If the input is: n N Nobody...
Frequency JND is around 0.5% for any two nearby frequencies (e.g., you can tell 100 Hz...
Frequency JND is around 0.5% for any two nearby frequencies (e.g., you can tell 100 Hz and 100.5 Hz notes apart, but maybe not 100 and 100.2 Hz), and the LFD is at best 7%. a. (2) What is the % difference between any two adjacent notes on figure A-1 which shows the standard Western 12 tone scale? Be careful not to skip the black notes for this problem! b. (2) But when two notes on a Western scale, even...
c++ 19.36 LAB: Output values below an amount - functions Write a program that first gets...
c++ 19.36 LAB: Output values below an amount - functions Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, and output all integers less than or equal to that value. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75 The 5 indicates that there are five integers...
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user...
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user to input two integers. - If both of them are greater than zero, then output their sum. - If only one integer is greater than zero, then output their difference. - Otherwise, output a message "your two number <0".
Write a program that input some number of cents (see less than 100), and output the...
Write a program that input some number of cents (see less than 100), and output the number of quarters, dimes, nickels and pennies needed to add up to that amount (thinking how a cashier needs to return you back some small changes).
C+ VISUAL STUDIO.. SHOW OUTPUT PLEASE Write a program that computes the number of possible combinations...
C+ VISUAL STUDIO.. SHOW OUTPUT PLEASE Write a program that computes the number of possible combinations to obtain a successful result of an arbitrary event. The formula for computing the possible combinations is given by: C(n,k)= n! / [k! * (n - k)!] where, n = the number of events k = number of success for that event Use the recursive function factorial explained in the chapter to compute the possible combinations.  The output should be displayed as follows: C( n,...
Write a program that creates an image of green and white horizontal stripes. Your program should...
Write a program that creates an image of green and white horizontal stripes. Your program should ask the user for the size of your image, the name of the output file, and create a .png file of stripes. For example, if the user enters 10, your program should create a 10x10 image, alternating between green and white stripes. A sample run of the program: Enter the size: 10 Enter output file: 10stripes.png Another sample run of the program: Enter the...
Write a machine language program to input two one-digit numbers, add them, and output the one-digit...
Write a machine language program to input two one-digit numbers, add them, and output the one-digit sum. There can be no space between the two one-digit numbers on input. Write the program in a format suitable for the loader and execute it on the Pep/9 simulator. It needs to be in hexadecimal, I am just confused on how to input numbers on the PEP/9 machine.
A 100 Hz sound wave is traveling through the air. If we increase the frequency to...
A 100 Hz sound wave is traveling through the air. If we increase the frequency to 200 Hz, this will ________ the wavelength. A. quadruple (4 x) B. cut in half (1/2 X) C. double (2 x) D. not change (stay the same) Two identical objects, each with a mass M, are attached to each other via a spring with a spring constant k. The two objects are oscillating such that one is always moving in the opposite direction and...