Question

In: Electrical Engineering

Using Arduino: Emulate dots and dashes telegraph transmission using a button and two LEDs. For instance,...

Using Arduino:

Emulate dots and dashes telegraph transmission using a button and two LEDs. For instance, if a button is held longer than 500ms, then the red LED will turn on to represent a dash "-". and a short press will turn on the green LED to represent a dot ".". The problem can be approached as a state machine where the states could include "wait_on_press", "delay_500ms", and "read_btn_val".

Solutions

Expert Solution

First we define pins where the red LED, green LED and buttons are present. This is done in the void setup part of the code. Following this we write the actual code in the void loop. In order to use least external components the internal pull up resistor is used on the button pin. This means that whenever the button is pressed the pin will transition from HIGH to LOW. The code is given below. For easy readability the snapshot of the code in Arduino IDE is also attached.

#define red_led_pin 12

#define green_led_pin 11

#define button_pin 10

void setup() {

// put your setup code here, to run once:

pinMode(red_led_pin,OUTPUT);

pinMode(green_led_pin,OUTPUT);

pinMode(button_pin,INPUT_PULLUP);

}

void loop() {

// put your main code here, to run repeatedly:

if(digitalRead(button_pin) == LOW) // If button is pressed

{

delay(500); // wait for 0.5 second

if(digitalRead(button_pin) == LOW) // Check if its still pressed

digitalWrite(red_led_pin,HIGH); // If yes then turn on red LED

else

digitalWrite(green_led_pin,HIGH);// Else turn on green LED

delay(250); // Wait for 0.25 seconds so that

// LEDs donot turn off quickly

digitalWrite(red_led_pin,LOW); // Turn off the red LED

digitalWrite(green_led_pin,LOW); // Turn of the green LED

}

}

Hope it helps. Fo any questions or doubt drop in a comment and I'll definitely get back to you. All the best.


Related Solutions

Arduino Project - Part 1 • Connect 3 LEDs on 3 digital pins • Blink LEDs...
Arduino Project - Part 1 • Connect 3 LEDs on 3 digital pins • Blink LEDs at: – 1 at 1 Hz – 2 at 4 Hz – 3 at 5 Hz • Blink LEDs at: – 1 Hz – 3 Hz – 5 Hz 36 What to submit • 2 Arduino files – one for 1,4,5 Hz blinking – one for 1,3,5 Hz blinking
Build a circuit for arcade game. You have 3 LEDS and 1 button. the LEDs should...
Build a circuit for arcade game. You have 3 LEDS and 1 button. the LEDs should recycle through 000,100,110,111,011, 001(back to 000). The user needs to hit the button during the 111 cycle 3 times in a row to win. The win is shown as an LED which is HIGH if the user won the last attempt of 3 presses. The win LED will be LOW otherwise
FOR ARDUINO PROGRAMMING NEED TO HAVE ALL LEDS FLASH 5 TIMES WHEN THE BOARD STARTS.
FOR ARDUINO PROGRAMMING NEED TO HAVE ALL LEDS FLASH 5 TIMES WHEN THE BOARD STARTS.
Add to this arduino sketch such that you can add three externally-connected LEDs to your circuit...
Add to this arduino sketch such that you can add three externally-connected LEDs to your circuit board. Modify this code such that the first LED turns on if the ADC output value is between 0 and 340, the second LED turns on if the ADC output value is between 341 and 680, and the third LED turns on if the ADC output value is above 680 int potpin=0;// initialize analog pin 0 int ledpin=13;// initialize digital pin 13 int val=0;//...
There is something wrong with my arduino lab. I want my four leds to light up...
There is something wrong with my arduino lab. I want my four leds to light up one after the other. Then the speaker plays music, and 4 leds change with music. But my code only makes one of them work. Please help me modify my code const int switchPin = 8; unsigned long previousTime = 0; int switchState = 0; int prevSwitchState = 0; int led = 2; // 600000 = 10 minutes in milliseconds long interval = 1000; int...
Write a program that captures the transmission of a character from an Arduino board over serial...
Write a program that captures the transmission of a character from an Arduino board over serial communication (UART)
Using Arduino a) write a program that uses two potentiometers to adjust the values displayed on...
Using Arduino a) write a program that uses two potentiometers to adjust the values displayed on the serial monitor. Have the two values displayed side by side via the serial monitor and each range from 0 to 255
Using Visual Basic 2017, Create a form with two textboxes and one button. A user enters...
Using Visual Basic 2017, Create a form with two textboxes and one button. A user enters the course she is taking in the first text box and then clicks on the button. Then if the user entered "Program Language" in the first text box, the second text box will show "Awesome pick!". If the user entered something else, the text box shows "Ok." Please write the correct code.
11.)   An experiment consists of rolling two fair dice and adding the dots on the two...
11.)   An experiment consists of rolling two fair dice and adding the dots on the two sides facing up. Assuming each simple event is as likely as any​ other, find the probability that the sum of the dots is greater than 2. The probability that the sum of the dots is greater than 2 is 12.) An experiment consists of rolling two fair dice and adding the dots on the two sides facing up. Find the probability of the sum...
Write a code for simple racing game (using dots) on c coding.
Write a code for simple racing game (using dots) on c coding.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT