CODE | Pulsating Lamp - Arduino Project 007

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

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

C01 | The Past and Present of the C Language

C01 | The Past and Present of the C Language

C语言教程01:C语言的前世今生程序设计语言的发展经历了从机器语言->汇编语言->高级语言的过程机器语言:是计算机最原始的语言,由 0 和 1 的代码构成,CPU 在工作的时候只认识机 器…

CODE | Ultrasonic Distance Alarm - Arduino Project 040

CODE | Ultrasonic Distance Alarm - Arduino Project 040

The sensor consists of two primary components: a transmitter and a receiver . The transmitter is res…

CODE | Liquid Crystal Displays-Custom Character - Arduino Project 023D

CODE | Liquid Crystal Displays-Custom Character - Arduino Project 023D

Before wiring the LCD screen to your Arduino board we suggest to solder a pin header strip to the 14…

CODE | Variables - Arduino Programming Basic

CODE | Variables - Arduino Programming Basic

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静…

Resitor Ohm's Law

Resitor Ohm's Law

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

Identifying Color-Band Resistors and Reading Their Values

Identifying Color-Band Resistors and Reading Their Values

色环电阻的识别与数值读取色环电阻是在电阻封装上(即电阻表面)涂上一定颜色的色环,来代表这个电阻的阻值。色环实际上是早期为了帮助人们分辨不同阻值而设定的标准。色环电阻应用还是很广泛的,如家用电器、电子仪…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.