Herzlich Willkommen im einzigen (deutschsprachigem) Picaxe-Forum.

Der Ursprung dieses Forum reicht bis in das Jahr 2008 zurück


4-flammige Adventskranzbeleuchtung mit Flackereffekt

#1 von BoomBoomMagic , 26.01.2019 18:47

Hier ein mal eine etwas extremere Anwendung mit der Funktion: Zufallsberechnung

Ein Adventskranz mit 4 LED's die per Zufall unterschiedlich flackern.

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 

#rem
 
---
V+ -| |- GND
C.5 -| |- B.0
C.4 -| |- B.1
C.3 -| |- B.2 / LED1
LED4 / C.2 -| |- B.3
C.1 -| |- B.4 / LED2
LED3 / C.0 -| |- B.5
---
 

 
#endrem
 
#picaxe 14m2
 

 
let dirsb=%11111111
let dirsc=%00000111
 

symbol PWM1_Duty = w0 ' b0+b1
symbol PWM2_Duty = w1 ' b2+b3
symbol PWM3_Duty = w2 ' b4+b5
symbol PWM4_Duty = w3 ' b6+b7
 
symbol PWM1_Duty_merken = w4 ' b8+b9
symbol PWM2_Duty_merken = w5 ' b10+b11
symbol PWM3_Duty_merken = w6 ' b12+b13
symbol PWM4_Duty_merken = w7 ' b14+b15
 
symbol Zaehler1 = b16
symbol Zaehler2 = b17
symbol Zaehler3 = b18
symbol Zaehler4 = b19
 

symbol Grundwert1 = 10
symbol Grundwert2 = 30
symbol Grundwert3 = 65
symbol Grundwert4 = 80
 

 

 
start:
 
random PWM1_Duty
if PWM1_Duty<>PWM1_Duty_merken then
PWM1_Duty_merken=PWM1_Duty
PWM1_Duty = PWM1_Duty // 240+1
PWM1_Duty = PWM1_Duty + Grundwert1
pwmout b.2,100,PWM1_Duty


for Zaehler1= PWM1_Duty to Grundwert1 step -1
pwmduty b.2,PWM1_Duty
next Zaehler1

for Zaehler1= Grundwert1 to PWM1_Duty
pwmduty b.2,PWM1_Duty
next Zaehler1
else
goto start
endif

goto start


'------------------------------------------
 
start1:
 
random PWM2_Duty
if PWM2_Duty<>PWM2_Duty_merken then
if PWM2_Duty<> PWM1_Duty_merken then
if PWM2_Duty<> PWM3_Duty_merken then
if PWM2_Duty<> PWM4_Duty_merken then

PWM2_Duty_merken=PWM2_Duty
PWM2_Duty = PWM2_Duty // 200+1
PWM2_Duty = PWM2_Duty + Grundwert2
pwmout b.4,100,PWM2_Duty


for Zaehler2= PWM2_Duty to Grundwert2 step -1
pwmduty b.4,PWM2_Duty
next Zaehler2

for Zaehler2= Grundwert2 to PWM2_Duty
pwmduty b.4,PWM2_Duty
next Zaehler2
else
goto start1
endif
endif
endif
endif

goto start1


'------------------------------------------
 
start2:
 
random PWM3_Duty
if PWM3_Duty<>PWM3_Duty_merken then
if PWM3_Duty<> PWM1_Duty_merken then
if PWM3_Duty<> PWM2_Duty_merken then
if PWM3_Duty<> PWM4_Duty_merken then

PWM3_Duty_merken=PWM3_Duty
PWM3_Duty = PWM3_Duty // 170+1
PWM3_Duty = PWM3_Duty + Grundwert3
pwmout c.0,100,PWM3_Duty


for Zaehler3= PWM3_Duty to Grundwert3 step -1
pwmduty c.0,PWM3_Duty
next Zaehler3

for Zaehler3= Grundwert3 to PWM3_Duty
pwmduty c.0,PWM3_Duty
next Zaehler3
else
goto start2
endif
 
endif
endif
endif

goto start2


'------------------------------------------
 
start3:
 
random PWM4_Duty
if PWM4_Duty<>PWM4_Duty_merken then
if PWM4_Duty<> PWM1_Duty_merken then
if PWM4_Duty<> PWM2_Duty_merken then
if PWM4_Duty<> PWM3_Duty_merken then

PWM4_Duty_merken=PWM4_Duty
PWM4_Duty = PWM4_Duty // 150+1
PWM4_Duty = PWM4_Duty + Grundwert4
pwmout c.2,100,PWM4_Duty


for Zaehler4= PWM4_Duty to Grundwert4 step -1
pwmduty c.2,PWM4_Duty
next Zaehler4

for Zaehler4= Grundwert4 to PWM4_Duty
pwmduty c.2,PWM4_Duty
next Zaehler4
else
goto start3
endif

endif
endif
endif

goto start3
 
 



Es werden 4 unabhängige Zufallszahlen generiert .
Die jeweilige Zufallszahl ein jeder LED wird zum einen jeweils mit deren eigenen, vorherigen Wert verglichen,
als auch mit den anderen 3 aktuellen LED-Werten , um zu vermeiden das 2 LED' s gleich flackern.

Das ganze läuft im Multitasking-Modus und mit der PWM-Funktion.

 
BoomBoomMagic
Beiträge: 879
Registriert am: 24.01.2019


   

elektronischer Würfel
8-Kanal KnightRider-Effekt

Picaxe Editor 5.5.5 Download
Update auf Picaxe Editor 5.5.6 Download
Picaxe Editor 6.x.x.x Download
Manual1.pdf        -      Grundwissen Download
Manual2.pdf        -      Befehle Download
Manual3.pdf        -      Beispiele Download


Press [Backspace] for back to Menu


Counter
Xobor Forum Software ©Xobor.de | Forum erstellen
Datenschutz