CODE | Pulsating Lamp - Arduino Project 007

RonWang3 years ago (2023-06-29)电子编程 COD340

You are now going try a more advanced method of controlling LEDs. So far, you have simply turned the LED on or off. Would you like to adjust the brightness of an LED? Can you do that with an Arduino? Yes, you can. Time to go back to basics.

项目7 调节LED灯的亮度Project 7 - Pulsating lamp

001 LED Blink Circuit

/* Coding Ron Wang
   July 2nd 2024
   Autaba support for coding hardware
 */
// Project 7 - Pulsating lamp
int ledPin = 10;
float sinVal;
int ledVal;
void setup() {
 pinMode(ledPin, OUTPUT);
}
void loop() {
 for (int x=0; x<180; x++) {
 // convert degrees to radians then obtain sin value
 sinVal = (sin(x*(3.1412/180)));
 ledVal = int(sinVal*255);
 analogWrite(ledPin, ledVal);
 delay(25);
 }
}

           

Share with Friends:

Related Articles

CODE | LED Dot Matrix Display Pong Game - Arduino Project 022

CODE | LED Dot Matrix Display Pong Game - Arduino Project 022

This project was hard going and a lot to take in. So, for Project 22 you are going to create a simpl…

Arduino software Download

Arduino software Download

Arduino Web EditorStart coding online and save your sketches in the cloud. The most up-to-date versi…

Resitor Ohm's Law

Resitor Ohm's Law

Ohm's law states that the current through a conductor between two points is directly&n…

CODE | LED Dot Matrix Display Scrolling Message - Arduino Project 021

CODE | LED Dot Matrix Display Scrolling Message - Arduino Project 021

There are many different ways to drive LEDs. Using shift registers is one way and they have their a…

Electric Maker Beginner Tools Kit

Electric Maker Beginner Tools Kit

This assortment of tools has everything you need to get started tinkering with Sparkfun products and…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.