Problem 20 25 Points Write a program to simulate a caution l

Problem 2.0 (25 Points) Write a program to simulate a caution light with an LED connected to pin 9. Your program should not use the delay function. The caution light should blink every 2 seconds. (25 Points)

Solution

const int ledpin=9;

int ledstate= low;

long previoustime=0;

long interval=2;

void setup() {

pinmode(ledpin, OUTPUT);

}

Void loop()

{unsigned long currentTime=millis();

If(currentTime-previousTime>interval){

PreviousTime=currentTime;

If(ledstate==LOW)

Ledstate=HIGH;

Else

Ledstate=LOW;

Digitalwrite(ledpin,ledstate);

}

}

 Problem 2.0 (25 Points) Write a program to simulate a caution light with an LED connected to pin 9. Your program should not use the delay function. The caution

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site