CODE | Pulsating Lamp - Arduino Project 007

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

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

Coding | 锻炼孩子的逻辑思维

Coding | 锻炼孩子的逻辑思维

自然语言(人类的语言)和计算机语言之间有许多相似之处,学习计算机语言类似于学习一门外语语法。 计算机编程或者算法的难点和意义是,是编程思维和解决问题能力。程序设计早已不是程序员们独有的技术活了,很多国…

CODE | Light Sensor - Arduino Project 014

CODE | Light Sensor - Arduino Project 014

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp…

CODE | LED Traffic Light - Arduino Project 003

CODE | LED Traffic Light - Arduino Project 003

You are now going to create a set of traffic lights that will change from green to red, via amber, a…

CODE | MX1508 H-Driver Motor - Arduino Project 030B

CODE | MX1508 H-Driver Motor - Arduino Project 030B

MX1508 H-BridgeDual Motor DriverThe driver can drive up to two motors. The H-Bridge dual motor drive…

Mounting a Hard Drive on a CentOS Server

Mounting a Hard Drive on a CentOS Server

Centos服务器挂载硬盘1. 查看服务器上未挂载的磁盘(磁盘有普通磁盘,高效磁盘,SSD磁盘Bashfdisk -l…

CODE | Control Stepper Motor ULN2004A - Arduino Project 029

CODE | Control Stepper Motor ULN2004A - Arduino Project 029

Stepper motors, due to their unique design, can be controlled to a high degree of accuracy without a…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.