CODE | Pulsating Lamp - Arduino Project 007

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

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 | IR Remote Control - Arduino Project 049

CODE | IR Remote Control - Arduino Project 049

Got it — you’re looking into using an infrared (IR) sensor with an IR remote on…

CODE | RGB LED Mood Lamp - Arduino Project 008

CODE | RGB LED Mood Lamp - Arduino Project 008

In the last project, you learned how to adjust the brightness of an LED using the PWM capabilities o…

CODE | SD Card Information Basic - Arduino Project 042

CODE | SD Card Information Basic - Arduino Project 042

Arduino Programming Basic -- Reading and Writing to an SD CardSD cards have non-volatile flash memor…

About Arduino WIKI

About Arduino WIKI

Arduino (/ɑːrˈdwiːnoʊ/) is an open-source hardware and software company, project, and user community…

CODE | Line Following Robot - Arduino Project 030

CODE | Line Following Robot - Arduino Project 030

Project 30 Line Following RobotA line following robot is an autonomous vehicle that detects and foll…

 CODE | LCD Temperature Display - Arduino Project 024

CODE | LCD Temperature Display - Arduino Project 024

This project is a simple demonstration of using an LCD to present useful information to the user—in…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.