.:: Multi LED Fader ::.
Fades LEDs in and out
This program is a C# demo of what can be done with PIC, AVR or Arduino. It fades LEDs in and out at different speed, different directions and from a different start intensity. The output numbers should be used as PWM duty cycle.
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 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace ConsoleAppl { class Program { static void Main(string[] args) { int a = 0; int b = 100; int c = 20; int stp1 = 1; int stp2 = 1; int stp3 = -1; while (true) { a += stp1; b += stp2; c += stp3; if (a >= 255) { stp1 = -stp1; a = 255; } if (a <= 0) { stp1 = -stp1; a = 0; } if (b >= 255) { stp2 = -stp2; b = 255; } if (b <= 0) { stp2 = -stp2; b = 0; } if (c >= 255) { stp3 = -stp3; c = 255; } if (c <= 0) { stp3 = -stp3; c = 0; } Console.Clear(); Console.WriteLine("A: " + a.ToString()); Console.WriteLine("B: " + b.ToString()); Console.WriteLine("C: " + c.ToString()); Thread.Sleep(100); } } } } |