Question

Write an Energia sketch that measures how long the on-board push button has been depressed. Output...

Write an Energia sketch that measures how long the on-board push button has been depressed. Output the duration of the button press to the serial monitor window. please help

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I hope this will help

int pinNumber = 7;
int led = 13;
int cur;   
long millis_held;
long secs;
long prev_secs_held;
byte previous = HIGH;
unsigned long firstTime;

void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(pinNumber, HIGH);
}

void loop() {
cur = digitalRead(pinNumber);
if (cur == LOW && previous == HIGH && (millis() - firstTime) > 200) {
firstTime = millis();
}
millis_held = (millis() - firstTime);
secs = millis_held / 1000;
if (millis_held > 50) {

if (cur == LOW && secs > prev_secs_held) {
ledblink(1, 50, led);
}   
if (cur == HIGH && previous == LOW) {
if (secs <= 0) {
ledblink(1,750,led);
}
if (secs >= 1 && secs < 3) {
ledblink(10,200,led);
}
if (secs >= 3) {
Serial.print("It Works!!! Seconds held: ");
Serial.print(secs);
Serial.print(" Milliseconds held: ");
Serial.println(millis_held);
}
}
}

previous = cur;
prev_secs_held = secs;
}

void ledblink(int times, int lengthms, int pinnum){
for (int x=0; x<times;x++) {
digitalWrite(pinnum, HIGH);
delay (lengthms);
digitalWrite(pinnum, LOW);
delay(lengthms);
}
}

Add a comment
Know the answer?
Add Answer to:
Write an Energia sketch that measures how long the on-board push button has been depressed. Output...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with doing these tasks for code composer Lab 3 - Branching, Push Button...

    I need help with doing these tasks for code composer Lab 3 - Branching, Push Button and LEDs-Reading Assignment in this lab, we are going to control a LED via a push button- using general purpose digital 10 for both input (button) and output (LED) on port 1 - using Code Composer Studio. Furthermore, we are going to use a branch instruction to create an IF-ELSE structure in assembly to determine if the LED should be lit up based on...

  • Write a Verilog program to describe a sequential circuit that has input X and output Z....

    Write a Verilog program to describe a sequential circuit that has input X and output Z. Z goes to 1 whenever the last four X inputs (in four clock cycles) are 1001 or 0110. Use a switch (SW1) on the DE1 board for X and a red LED for Z. Use a push button as the clock input. Use both the Moore and Mealy models to describe the circuit.

  • help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or...

    help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or SAMW25 Xplained Pro 1) 2) USB cable 3) PC ELVIS II board 4) Program UART Write a program that uses the default UART interface of the SAMD21 microcontroller to communicate with over the the UART of the EDBG microcontroller. The EDBG chip will then convert the serial data and send this USB to the PC....

  • help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or...

    help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or SAMW25 Xplained Pro 1) 2) USB cable 3) PC ELVIS II board 4) Program UART Write a program that uses the default UART interface of the SAMD21 microcontroller to communicate with over the the UART of the EDBG microcontroller. The EDBG chip will then convert the serial data and send this USB to the PC....

  • help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or...

    help me, how can wright the code using ( atmel 7 ) ( GCC C ASF Board Project ) C/C++ Equipment and Materials SAMD21 or SAMW25 Xplained Pro 1) 2) USB cable 3) PC ELVIS II board 4) Program UART Write a program that uses the default UART interface of the SAMD21 microcontroller to communicate with over the the UART of the EDBG microcontroller. The EDBG chip will then convert the serial data and send this USB to the PC....

  • It's an Energia sketch using C language. We work with MSP430 Launchpad but you shouldn't need...

    It's an Energia sketch using C language. We work with MSP430 Launchpad but you shouldn't need it to write the code. I'm really stuck :( Problem 2 (50 points) One common method of outputting an "effective" analog signal is to use pulse width modulation or PWM. In this modulation scheme, a high frequency square wave is switched on and off with a duty cycle determined by the desired output intensity, where Duty Cycle = Time spend "on" Total period 50%...

  • I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED str...

    I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...

  • c++ please help Write a program that has a general welcome statement (such as “Welcome! How...

    c++ please help Write a program that has a general welcome statement (such as “Welcome! How is your day going?”) in a string and ask the user to input his/her name and the day of the week. Then insert them into the welcome message to make it personalized and output the message. (example: user inputs Matt and Wednesday, the output should be “Welcome Matt! How is your Wednesday going?”).

  • Help with Q9 pls Q8 Q9 A pharmaceutical company has created a new drug to decrease how long patients suffer from a run...

    Help with Q9 pls Q8 Q9 A pharmaceutical company has created a new drug to decrease how long patients suffer from a runny nose while having a cold. It is known that without treatment, on average, people report having a runny nose for 60 hours while having a cold. A test is organised for this new drug, hoping to prove the drug indeed decreases the duration of symptoms: 154 patients use it at the first sign of a runny nose...

  • Did I answer correclty question 2 and 3 based on the scenario given? scussion Board 5...

    Did I answer correclty question 2 and 3 based on the scenario given? scussion Board 5 0 Ms. C, 72 years old, has diabetes mellitus, hypertension, rheumatoid arthritis (RA), and coronary artery disease. She lives alone. She recently was discharged from the hospital after treatment for an acute myocardial infarction. She had been doing well before this admission. You are the home health nurse assigned to visit Ms. C. Ms. C's son tells you he is concerned that his mother...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT