CODE | Pulsating Lamp - Arduino Project 007

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

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

C05 |   C/C++ Develop Environment

C05 | C/C++ Develop Environment

C语言教程05: C/C++开发环境C 语言编译器可以分为 C 和 C++两大类,其中 C++是 C 的超集,也支持 C 语言编程。事实上,编译器的选择不是最重要的,它们都可以完成基本的 C 语言编译…

How to Choose the Right Wire Stripper Tool?

How to Choose the Right Wire Stripper Tool?

剥线钳是弱电工程师、内线电工、电动机修理、仪器仪表电工及电子制作爱好者常用的工具之一,用来供操作者剥除电线头部的表面绝缘层。剥线钳可以使得电线被切断的绝缘皮与电线分开,可以在不损坏内部金属线层的情况下…

Install PrestaShop 1.7 Version

Install PrestaShop 1.7 Version

现在很多国内的公司为了拓展对外业务,开始采用更先进的电子商务软件,如美国的Amazon,加拿大的Shopify,法国的PrestaShop等都有很多用户在使用,对于商业初期的低成本尝试,开源软件Pre…

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…

Arduino software Download

Arduino software Download

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

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.