Question

In: Computer Science

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.

Solutions

Expert Solution

I think you want the flashes to stop after 5 on/off repetitions or to have 5 seconds between the flash sequences.

You need to have a variable to count the number of flashes and only increment that variable when a flash actually happens. When the 5 flashes are completed your code will know not to flash anymore.



const byte ledPin = 13;
byte flashCount = 0;
byte state = 0;
unsigned long waitStart;
unsigned long shortPeriod = 500;
unsigned long longPeriod = 5000;
unsigned long currentTime;

void setup()
{
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  waitStart = millis();
}

void loop()
{
  switch (state)
  {
    case 0:
      currentTime = millis();
      if (currentTime - waitStart >= shortPeriod)
      {
        digitalWrite(ledPin, !digitalRead(ledPin));
        waitStart = currentTime;
        flashCount++;
        if (flashCount == 10)
        {
          state = 1;
        }
      }
      break;
      
    case 1:
      currentTime = millis();
      if (currentTime - waitStart >= longPeriod)
      {
        waitStart = currentTime;
        flashCount = 0;
        state = 0;
      }
      break;
  }
}

Related Solutions

FOR an mbed LPC 1768 have 4 LEDs flash 5 times in turn (i.e., LED1 flashes...
FOR an mbed LPC 1768 have 4 LEDs flash 5 times in turn (i.e., LED1 flashes 5 times, followed by LED2, then followed by LED3, and finally followed by LED4, and it repeats). Design the hardware connection of your LEDs to mbed. Build your circuit and include all the required information about your hardware design in your lab report. Create a new program to fulfill the function of the blinking LEDs as described in last step. I need the C++...
I need a Verilog code that makes the LEDs on the FPGA board works like this....
I need a Verilog code that makes the LEDs on the FPGA board works like this. https://image.ibb.co/mu5tnS/6.gif There are 16 LEDs in the FPGA board
When does a corporation need a board of directors?
When does a corporation need a board of directors?
Write a program in Arduino that, when it takes in a voltage range (0 to 5...
Write a program in Arduino that, when it takes in a voltage range (0 to 5 volts), gives a corresponding servo motor angle with a range from 0 to 180 degrees.
1. The parents of a 5-year old child wish to have $250,000 when the child starts...
1. The parents of a 5-year old child wish to have $250,000 when the child starts college at the age of 18. How much should they deposit monthly in an account that pays 4.5% compounded monthly to achieve their goal? 2. A 25-year old saves for retirement by making monthly deposits of $1000 in an account that pays 4.9% compounded monthly. How much would be in the account at retirement age of 65? Please provide answers ASAP. Thanks
the board of a company must ensure that there are kept at all times accounting records...
the board of a company must ensure that there are kept at all times accounting records that … correctly record the transactions of the company” – section 194 of the Companies Act 1993.
Suppose that 28% of all Americans have experienced times when they haven’t been able to afford...
Suppose that 28% of all Americans have experienced times when they haven’t been able to afford sufficient food. Separately, you sample 801 Americans who are financially less well-off than average Americans and find that 38% reported that there had been times in the last year when they had not been able to afford sufficient food. Does this indicate that the problem is more severe among those American who are less well-off? Test an appropriate hypothesis and state your conclusion. Make...
Suppose that 28% of all Americans have experienced times when they haven’t been able to afford...
Suppose that 28% of all Americans have experienced times when they haven’t been able to afford sufficient food. Separately, you sample 801 Americans who are financially less well-off than average Americans and find that 38% reported that there had been times in the last year when they had not been able to afford sufficient food. Does this indicate that the problem is more severe among those American who are less well-off? Test an appropriate hypothesis and state your conclusion. Make...
I need C++ programming with output. I have tried other programming and it does not work....
I need C++ programming with output. I have tried other programming and it does not work. So please give me the one that actually works. Assignment 1 Design your own linked list class that works as a template class. It should provide member functions for appending, inserting and deleting nodes. The destructor should destroy the list. The class should also provide a member function that will display the contents of the list to the screen. The class should also provide...
( strategic management )  When does a corporation need a board of d directors?
( strategic management )  When does a corporation need a board of d directors?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT