Introduction
Fade the LEDs with the trimmer. Use the LCD to print the selected PWM value.
What you will need - Hardware
We will use:
Connections
LEDs and Trimmer
Nokia 5110 LCD (Blue PCB)
|
|
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* * === Ardumotive Shield for Arduino UNO Board === * Arduino Tutorial: Fade LEDs * Dev Michalis Vasilakis/Date 24/3/2018/http://ardumotive.com */ #define pinLED1 9 #define pinLED2 10 #define pinLED3 11 #define trimmer A1 #include <Adafruit_GFX.h> #include <Adafruit_PCD8544.h> Adafruit_PCD8544 display = Adafruit_PCD8544(3,4,5,6,7); int pwm=255; void setup() { // Put your setup code here, to run once: // Define LED pins as outputs: pinMode(pinLED1, OUTPUT); pinMode(pinLED2, OUTPUT); pinMode(pinLED3, OUTPUT); display.begin(); display.setContrast(50); display.clearDisplay(); // clears the screen and buffer } void loop() { // put your main code here, to run repeatedly: pwm = map(analogRead(A1),0,1024,0,255); display.setTextSize(1); display.println("PWM Fade:"); display.println(""); display.setTextSize(3); display.println(pwm); display.display(); fadeLeds(pwm); display.clearDisplay(); // clears the screen and buffer } void fadeLeds(int pwm){ analogWrite(pinLED1, pwm); analogWrite(pinLED2, pwm); analogWrite(pinLED3, pwm); } |
Download the code from here and open it with Arduino IDE. Inside you will also find the library files.
|
|