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.
//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
}
Get Answers For Free
Most questions answered within 1 hours.