Question

In: Computer Science

Write the following in C language for Arduino: Write a program that turns on the LED...

Write the following in C language for Arduino:

Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change.

  • Remember you are going to need to use a PWM pin and use the "analogWrite" command.
  • The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for each step.

Solutions

Expert Solution

//analogWrite(0) means a signal of 0% duty cycle.
//analogWrite(255/4=64)means a signal of 25% duty cycle
//analogWrite(255/2=127) means a signal of 50% duty cycle.
//analogWrite(255*3/4=191) means a signal of 100% duty cycle
//analogWrite(255) means a signal of 100% duty cycle

//Initializing LED Pin
int led_pin = 6;//connect led to 6th pin
void setup() {
//Declaring LED pin as output
pinMode(led_pin, OUTPUT);
}
void loop() {
//The Arduino IDE has a built in function “analogWrite()” which can be used to generate a PWM signal.
//The frequency of this generated signal for most pins will be about 490Hz and we can give the value from 0-255 using this function.
analogWrite(led_pin, 255/4);//for 25% brightness
delay(1);//delay 1 second
analogWrite(led_pin, 255/2);//for 50%brightness
delay(1);//delay 1 second
analogWrite(led_pin, (255*3)/4);//for 75% brightness
delay(1);//delay 1 second
analogWrite(led_pin, 255);//for 100% brightness
delay(1);//delay 1 second
analogWrite(led_pin,0); //for 0% brightness
delay(1);//delay 1 second
}

code compiled:


Related Solutions

Write the following in C language for Arduino: Write a program that increases the LED brightness...
Write the following in C language for Arduino: Write a program that increases the LED brightness in five steps with each press of the button. Remember you are going to using a digital input and the "digitalRead" command. You are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON 2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION THANK YOU!
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN DARK CONDITIONS AND OFF IN LIGHT CONDITIONS 2. LED 4 TURNS ON WITH FIRST BUTTON PRESS AND STAYS ON UNTIL A SECOND BUTTON PRESS
Write a program in C language that implements the logic of Binary Trees with the following...
Write a program in C language that implements the logic of Binary Trees with the following requirements: 1- Elements of the tree should be read from the user. 2- Keep the binary tree heigh-balanced that is the absloute value of ((hight of left sub-tree) - ( height of right sub-tree)) should not be greater than 1. If so, then the binary tree is no longer balanced. Hint: The best approach is to maintain balance during insertion. *Remember, we are talking...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
Write an assembly language program that corresponds to the following C program ****Please give correct answer...
Write an assembly language program that corresponds to the following C program ****Please give correct answer using Pep/9 machine**** int num1; int num2; ;int main () { scanf("%d", &num1); num2 = -num1; printf("num1 = %d\n", num1); printf("num2 = %d\n", num2); return 0; }
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot : raw data, delay data (int) Purpose: Delay Block (**Using Class**) Input : u(t) Output : o(t)=u(t-h) sample time=0.02 Delay (h) = 0.4
Write Arduino program to implement wiring three momentary switches to the Arduino board
Write Arduino program to implement wiring three momentary switches to the Arduino board
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
C language you are to write a a program that will first read in the heights...
C language you are to write a a program that will first read in the heights and weights of a series of people from a file named values.dat. Create this file using your editor so that each line contains a height and corresponding weight. For instance, it might look likea: 69.0 125.0 44.0 100.0 60.0 155.0 49.0 190.0 65.0 115.0 50.0 80.0 30.0 129.0 72.0 99.0 68.0 122.0 50.0 105.0 and so on. The formula for the standard deviation of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT