Question

Lab 1-Lab Portion Part I Copy the Blink program from Figure 1-13 (page 17) in the textbook and run it on your Arduino. After
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans part 1)

Morse SOS code of light means the LED must blink 3 times for short duration and 3 times for long duration and continue in this manner.


int LED = 13;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
int i;
for (i=0;i<3;i++)
{
digitalWrite(LED, HIGH);   
delay(250);   
digitalWrite(LED, LOW);   
delay(250);
}
  
for (i=0;i<3;i++)
{
digitalWrite(LED, HIGH);   
delay(750);   
digitalWrite(LED, LOW);   
delay(750);
}
}

Ans 2)

CODE:

int led = 11; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 25;// how many points to fade the LED by

int pushButton1 = 2;
int pushButton2 = 4;
// the setup routine runs once when you press reset:
void setup() {
// declare pin 11 to be an output:
pinMode(led, OUTPUT);
  
pinMode(pushButton1, INPUT);
pinMode(pushButton2, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  
int buttonState1 = digitalRead(pushButton1);
int buttonState2 = digitalRead(pushButton2);
  
if(buttonState1 == HIGH)
{
brightness = brightness + fadeAmount;
analogWrite(led, brightness);
}
  
if(buttonState2 == HIGH)
{
brightness = brightness - fadeAmount;
analogWrite(led, brightness);
}
Serial.print(brightness);

delay(100);
}

The maximum value for brightness is 255 and minimum value is 0

In order to overcome this problem some boundary condition must be set like if brightness = 255 then it will remain fixed at that value and won't increase further. Similarly it becomes constant when minimum value = 0 is reached.

Add a comment
Know the answer?
Add Answer to:
Lab 1-Lab Portion Part I Copy the Blink program from Figure 1-13 (page 17) in the textbook and run it on your Arduino. After verifying that the Blink program works, modify the program to make the...
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
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