RGB Fader mit Tasten Attiny2313(Bascom)

OP #1967206
Lesenswert?

*Guten Morgen,
Es ist mir nicht begreiflich, warum ich nicht den Color_delay mit 
Tastern ändern kann. +-
Vielleicht ist mein Ansatz auch falsch ?*


1
$regfile = "attiny2313.dat"                                 ' specify the used micro
2
$crystal = 800000                                        ' used crystal frequency
3
$hwstack = 64
4
$swstack = 16
5
$framesize = 21
6
Config Pinb.2 = Output                                      'Die PWM-Pins als Output definieren
7
Config Pinb.3 = Output                                  'Die PWM-Pins als Output definieren
8
Config Pinb.4 = Output                                      'Die PWM-Pins als Output definieren
9
Config Pind.0 = Input
10
Config Pind.1 = Input
11
Config Pind.2 = Input
12

13
'Die Timer auf PWM-Modus stellen
14
'Die PWM-Register haben eine Breite von 8 Bit - also Werte von 0 bis 255
15
'Wobei 0 = 0% Helligkeit und 255 = 100% Helligkeit bedeuten
16
Config Timer0 = Pwm , Pwm = On , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
17
Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
18

19

20
'Die Timer starten
21
Enable Timer0
22
Enable Timer1
23
                                            ' Interessanterweise MUSS man für OC2 Enable benutzen, sonst passiert nix!
24
Start Timer0
25
Start Timer1
26

27

28
'Die PWM-Register zuweisen
29
Led1 Alias Ocr1bl                                       'PWM-Pin 1 - Red
30
Led2 Alias Ocr1al                                       'PWM-Pin 2 - Green
31
Led3 Alias Ocr0a                                            'PWM-Pin 3 - Blau
32
Taste1 Alias Pind.0
33
Taste2 Alias Pind.1
34
Taste3 Alias Pind.2
35

36

37
'ein Paar Variablen Deklarieren
38
Dim Color_delay As Byte
39
Dim Color_stop As Byte
40
Dim Rgb As Byte
41

42

43
'Startwert für die Schleife
44
Rgb = 0
45

46
'Farbwechsel Geschwindigkeit pro Schritt (empfohlen 1-15)  1=schnell  15=langsam
47
Color_delay = 10
48

49
'Dauer der Pause bei der Grundfarbe (empfohlen 1-10)
50
Color_stop = 2
51

52

53
Do
54
If Taste2 = 1 Then Load Color_delay + 1 End If
55
If Taste3 = 1 Then Load Color_delay - 1 End If
56
If Taste1 = 1 Then
57

58
   If Rgb = 0 Then
59
   Incr Led1
60
   Decr Led3
61
   Waitms Color_delay
62
   End If
63

64
   If Led1 = 255 Then
65
   Rgb = 1
66
   Led3 = 0
67
   Wait Color_stop
68
   End If
69

70
   If Rgb = 1 Then
71
   Decr Led1
72
   Incr Led2
73
   Waitms Color_delay
74
   End If
75

76
   If Led2 = 255 Then
77
   Rgb = 2
78
   Led1 = 0
79
   Wait Color_stop
80
   End If
81

82
   If Rgb = 2 Then
83
   Decr Led2
84
   Incr Led3
85
   Waitms Color_delay
86
   End If
87

88
   If Led3 = 255 Then
89
   Rgb = 0
90
   Led2 = 0
91
   Wait Color_stop
92
   End If
93

94
 Else
95

96

97
End If
98

99
Loop
100
End
Gast #1967340
Lesenswert?

Poti wäre eine elegante Lösung !!!

Ich könnte mir folgendes vorstellen :

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc


Adc0 = Getadc(0)
Select Case Adc0
Case 0 To 50 :
Color_delay=10

Case 51 To 100 :
Color_delay=15


usw...
Gast #1967374
Lesenswert?

Denke schon, der ADC wert ist normal zwischen 0 und 255.

Poti ist an PC.0

Tipp : Am Anfang schliesse ich eine LCD Display an für Testzwecke un zu 
sehen welche Werte gerade anstehen....es gibt mit Sicherheit auch noch 
andere Möglichkeiten...
Gast #1967415
Lesenswert?

In Bascom ist recht einfach. Du definierst die Anschlüsse vom LCD wo an 
Atmega angeschlossen ist . BSP :

Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , _
      Db7 = Portb.3 , E = Portb.4 , Rs = Portb.5
Config Lcd = 16 * 2
Cls
Cursor Off

dann kannst einfach in der Do - Loop schleife Werte anzeigen lassen :


Locate 1 , 1      ( Position )
Lcd "Wert"       ( Fix Text )
Locate 2,1
Lcd Color_delay ( welche Wert soll angezeigt werden.)



So dann sieht an der Anzeige :
Wert
122 ( Bsp )

PS: LCD ist sehr günstig in Polen oder HongKong. Habe für 2 Euro 16x2 
Blau/weiss bestellt )
OP #1968684
Lesenswert?

So habe nun den Code auf einen atmega32 umgeschrieben, jedoch nun 
erhalte ich die Fehlermeldung:

ERROR : 269  last Line END SELECT expected.
Müsste heißen die adc messung müsste auch gestoppt werden oder?

lG Ben



1
$regfile = "m32def.dat"                                     ' specify the used micro
2
$crystal = 800000                                        ' used crystal frequency
3
$hwstack = 64
4
$swstack = 16
5
$framesize = 21
6
Config Pind.4 = Output                                      'Die PWM-Pins als Output definieren
7
Config Pind.5 = Output                                      'Die PWM-Pins als Output definieren
8
Config Pind.7 = Output                                      'Die PWM-Pins als Output definieren
9
Config Pina.0 = Input
10

11

12
'Die Timer auf PWM-Modus stellen
13
'Die PWM-Register haben eine Breite von 8 Bit - also Werte von 0 bis 255
14
'Wobei 0 = 0% Helligkeit und 255 = 100% Helligkeit bedeuten
15
Config Timer0 = Pwm , Pwm = On , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
16
Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
17
Config Adc = Single , Prescaler = Auto , Reference = Avcc
18

19

20

21
'Die Timer starten
22
Enable Timer0
23
Enable Timer1
24
                                            ' Interessanterweise MUSS man für OC2 Enable benutzen, sonst passiert nix!
25
Start Timer0
26
Start Timer1
27

28

29
'Die PWM-Register zuweisen
30
Led1 Alias Ocr2                                             'PWM-Pin 1 - Red
31
Led2 Alias Ocr1bl                                           'PWM-Pin 2 - Green
32
Led3 Alias Ocr1al                                           'PWM-Pin 3 - Blau
33
Taste1 Alias Pind.0
34

35

36

37
'ein Paar Variablen Deklarieren
38
Dim Color_delay As Byte
39
Dim Color_stop As Byte
40
Dim Rgb As Byte
41
Dim Adc0 As Byte
42

43
'Startwert für die Schleife
44
Rgb = 0
45

46
'Farbwechsel Geschwindigkeit pro Schritt (empfohlen 1-15)  1=schnell  15=langsam
47
Color_delay = 10
48

49
'Dauer der Pause bei der Grundfarbe (empfohlen 1-10)
50
Color_stop = 2
51

52

53
Do
54

55
Start Adc
56
Adc0 = Getadc(0)
57
Select Case Adc0
58
Case 0 To 50 :
59
Color_delay = 10
60
Case 51 To 100 :
61
Color_delay = 15
62

63

64

65

66
   If Rgb = 0 Then
67
   Incr Led1
68
   Decr Led3
69
   Waitms Color_delay
70
   End If
71

72
   If Led1 = 255 Then
73
   Rgb = 1
74
   Led3 = 0
75
   Wait Color_stop
76
   End If
77

78
   If Rgb = 1 Then
79
   Decr Led1
80
   Incr Led2
81
   Waitms Color_delay
82
   End If
83

84
   If Led2 = 255 Then
85
   Rgb = 2
86
   Led1 = 0
87
   Wait Color_stop
88
   End If
89

90
   If Rgb = 2 Then
91
   Decr Led2
92
   Incr Led3
93
   Waitms Color_delay
94
   End If
95

96
   If Led3 = 255 Then
97
   Rgb = 0
98
   Led2 = 0
99
   Wait Color_stop
100
   End If
101

102
End If
103

104
Loop
105

106
End

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren