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?
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...
( strategic management )  When does a corporation need a board of d directors?
( strategic management )  When does a corporation need a board of d directors?
C# programming When a loop might execute many times, it becomes increasingly important to consider the...
C# programming When a loop might execute many times, it becomes increasingly important to consider the number of evaluations that take place. How can considering the order of evaluation of short-circuit operators affect the performance of a loop?
Scenario The enrolment process starts when a student submits all the required forms and documentation to...
Scenario The enrolment process starts when a student submits all the required forms and documentation to the online enrolment system. As a first step, the academic qualifications of the student are verified with an external agency, and the student is given an academic score. Then, at the closing date of applications, a selection is made of the students based on their academic merits. Then, the payment is performed followed by a visa application for international students, while in the meantime...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT