The so-called “breathing lamp” is to control the flashing process of LED lamp through program, which is rhythmic like breathing. There is a process of brightness gradient.

Let’s start with a rendering:

Design of heart-shaped LED flashing controlled by 51 single chip microcomputer

This is an unmodified look, but after a simple decoration, it turns into a super loving thing

Design of heart-shaped LED flashing controlled by 51 single chip microcomputer

Production process:

1 //******************************

2 / / 51 single chip microcomputer simulates breathing lamp

three

4 // menglei

5 / / p0.0 is connected to an LED, and the status 0 is on

six

seven

eight

9 #include

10 #define N 2 / / rate of light and dark

11 #define t 800 / / PWM cycle

12 #define T1 1400

13 #define T2 900

14 //sbit led0=P0^0;

15 //======================

16 void pwm(int x)

17 {

18 while(x–);

19 }

20 //======================

twenty-one

22 void flash1(void){

23 int t = 0;

24 char f = 0;

25 int count = 5;// 5 times, the number of times each function is executed

26 while(1){

27 P0 = 0x00;

28 pwm(t); // Toff, light up time

29 //led0=1;

30 P0 = 0xff;

31 pwm(T-t+100);// Ton, dark time

32 if(!f) t+=N+1;// The light rate is fast, simulating respiration

33 else t-=N;// Slow dark rate

34 If (T) {f = 1; t = t;} / / when the maximum value is exceeded, the maximum value is returned and the flag is dark

35 If (T < 0) {f = 0; t = 0;} / / when the minimum value is exceeded, the minimum value is returned and the flag is on

36 // count–;

37 }

38 }

39 void main()

40 {

forty-one

42 while(1)

43 {

44 flash1();

45 }

46 }

Leave a Reply

Your email address will not be published. Required fields are marked *