Mikrocontroller und Digitale Elektronik
›
Thread
Arduino Mega Lauflicht mit TPIC6B595
JN
Jonas N.
Gast
21.08.2017 17:40
#5118132
Hallo,
ich habe einen Sketch angehangen wo ich es schon hinbekommen habe das
die LED s alle nacheinander angehen allerdings auch direkt wieder
ausgehen, mein Ziel ist es die LED s alle nacheinander angehen zu lassen,
so das sie auch an bleiben und wenn die Anzahl erreicht ist alle wieder
ausgehen und das ganze von vorne beginnen kann.
Ich hoffe mir kann einer helfen.
1 #include <SPI.h>
2
3 // PIN SETUP
4 const int latchPin = 53 ; // SS (SPI) -> RCK (TPIC6B595)
5 const int clockPin = 52 ; // SCK (SPI) -> SRCK (TPIC6B595)
6 const int dataPin = 51 ; // MOSI (SPI) -> SER IN (TPIC6B595)
7 const int clearPin = 40 ; // D40 (ard) -> SRCLR (TPIC6B595)
8
9 int pause = 1000 ;
10
11 void setup () {
12
13 Serial . begin ( 9600 );
14
15 pinMode ( clockPin , OUTPUT );
16 pinMode ( dataPin , OUTPUT );
17 pinMode ( latchPin , OUTPUT );
18 pinMode ( clearPin , OUTPUT );
19
20 digitalWrite ( clearPin , HIGH );
21
22 SPI . beginTransaction ( SPISettings ( 16000000 , MSBFIRST , SPI_MODE0 ));
23 }
24
25 int count = 8 ;
26 byte pos ;
27
28 int totalBytes = 2 ;
29
30 int totalBits = totalBytes * 8 ;
31
32 byte bytes [] = {
33 B00000000 ,
34 B00000000 ,
35 B00000000 ,
36 B00000000 ,
37 B00000000 ,
38 B00000000 ,
39 B00000000 ,
40 B00000000 ,
41 B00000000 ,
42 B00000000 ,
43 B00000000 ,
44 B00000000 ,
45 B00000000
46 };
47
48 void loop () {
49
50 for ( int theByte = 0 ; theByte < totalBytes ; theByte ++ ) {
51 bytes [ theByte ] = B00000000 ;
52
53 for ( int theBit = 0 ; theBit < 8 ; theBit ++ ) {
54 if ( theByte == int ( count / 8 )) {
55 if ( theBit == pos ) {
56 bitWrite ( bytes [ theByte ], theBit , 1 );
57 }
58 }
59 }
60 SPI . transfer ( bytes [ theByte ]);
61 }
62
63 pulsePin ();
64 delay ( pause );
65
66 //update count
67 count ++ ;
68 if ( count >= totalBits ) count = 0 ;
69 pos = count % 8 ;
70
71 Serial . println ( int ( count / 8 ));
72 Serial . print ( " \t " );
73 Serial . println ( count % 8 );
74 }
75
76 void write ( byte bits ) {
77
78 SPI . transfer ( bits );
79 pulsePin ();
80 }
81
82 void pulsePin () {
83
84 digitalWrite ( latchPin , LOW );
85 digitalWrite ( latchPin , HIGH );
86 }
D
DerFlo
Gast
21.08.2017 17:53
#5118149
Plus 1 rechnen , anzeigen lassen, bit nach links verschieben und plus 1
rechnen, anzeigen lassen usw.
JN
Jonas N.
Gast
21.08.2017 21:19
#5118371
Ich habe absolut keine Ahnung wie ich das machen soll, kannst du das
vielleicht in meinem Code ändern/hinzufügen?
↑ Nach oben
← Zurück zu Mikrocontroller und Digitale Elektronik
Antwort schreiben