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
(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...
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...
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...
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).
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 C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
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...
Review the following output from a chi-square test, and answer the questions below. Chi-Square Test Frequencies:Preference...
Review the following output from a chi-square test, and answer the questions below. Chi-Square Test Frequencies:Preference Observed N Expected N Residual Nuts & Grits 9 20.0 -11.0 Bacon Surprise 27 20.0 7.0 Dimples 16 20.0 -4.0 Froggy 17 20.0 -3.0 Chocolate Delight 31 20.0 11.0 Total 100 Test Statistics Preference Chi-Square 15.800a df 4 Asymp. Sig. .003 a 0 cells (0.0%) have expected frequencies less than 5. The minimum expected cell frequency is 20.0. Answer the following questions about this...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an n-by-n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note that...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...